Questions tagged [elementcriteriamodel]

Questions having to do with Craft's ElementCriteriaModel, which is used to return a set of elements narrowed by a variety of parameters.

Filter by
Sorted by
Tagged with
1 vote
1 answer
119 views

Entries inside controller

I'm trying to bring back a list of entries from a section. Currently I have the following: $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'airports'; $...
1 vote
0 answers
52 views

Find category through ajax using ElementCriteriaModel

I'm trying to run a controller action with ajax in a new plugin I'm making. The action needs to return all categories from a group, so nothing impossible here. When I run the actionUrl in the ...
1 vote
0 answers
59 views

When constructing an ECM, is it possible to compare two values?

My section has two numeric fields, lorem and ipsum. It's possible for users to enter any integer they want into these two fields. I want to grab all results where lorem is greater than ipsum. Here's ...
  • 23.8k
1 vote
1 answer
111 views

getCriteria not working as expected with boolean field types

I have a custom content table for an elementType. I have a few fields set up in my Record as boolean. The two fields are approved and denied I have to search the database where both fields are set to ...
1 vote
1 answer
834 views

How can I filter Craft Commerce products by price

I'm trying to use price as a parameter for filtering my Craft Commerce products, but I cannot get it to work. I think the problem is with the way that I'm referring to the product price, but at the ...
1 vote
1 answer
58 views

list available parameters of variable

Is there a way to print all of the available parameters/handles when I set a variable? For example if I put {% set orders = craft.commerce.orders.find() %} is there a way to list out the available ...
  • 543
2 votes
2 answers
403 views

Using getCriteria with a custom element type

I've setup a custom element type for badges for a system I'm building, but I've run into some trouble trying to query for badges using craft()->elements->getCriteria(ElementType::Badges_Badge);, ...
1 vote
1 answer
249 views

Eager Loading Image Transforms In Plugin

The craft docs on eager loading show you how to eager load image transforms in twig. {% set entries = craft.entries({ with: [ ['coolImage', { withTransforms: ['transform'] }] ] }) %} ...
  • 917
2 votes
1 answer
574 views

Accessing Eager Loaded Transforms

The craft docs on eager loading show you how to eager load image transforms in twig. {% set entries = craft.entries({ with: [ ['coolImage', { withTransforms: ['transform'] }] ] }) %} ...
  • 917
1 vote
1 answer
177 views

Figuring out why my image is not working in the template

Possibly a very easy question. Let me explain my flow: I created an asset folder (images) I added the folder in the assets I created in image transforms 'square' which is an image of 500 by 500px. I ...
2 votes
1 answer
184 views

Fixed order with limited set, then resume normal order

I have a news page (/news). You can open an article (i.e. /news/test-article) which uses the same listing template, but has an accordion open with content for that article (javascript/push state magic)...
  • 917
1 vote
1 answer
274 views

how can I filter to get only root categories in elementapi.php

I tried to build JSON-API which returns all categories, whose result will be cascaded like "nav" tag with craft twig templating (see: https://craftcms.com/docs/templating/craft.categories ). to get ...
3 votes
1 answer
63 views

Performance when loading lots of Elements but only need limited data

The performance of the ElementCriteriaModel for lookups is killing me. I have 300 or so "People" entries in a craft site and trying to load them just for a basic listing page takes forever. There's ...
  • 917
2 votes
1 answer
348 views

Filter entries in the CP based on custom permission

We started a new project, a website that lists products based on regions (for example US and Europe). We have all products in 1 channel (to make it dynamic to add more regions later on) and have a ...
  • 1,456
1 vote
1 answer
696 views

Element API: return a related entry's asset data with entry data

I'm producing a list of entries that each use an image asset from a related entry. I see in this ticket how to get an asset's data, and I've combined that with how I learned to output an object's ...
  • 1,942
1 vote
1 answer
244 views

Complex Conditionals with ElementCriteriaModel / Element API

Working with the Element API for the first time and I'm having a bit of a hard time finding any kind of documentation regarding writing more complex conditionals using the ElementCriteriaModel. What ...
1 vote
1 answer
67 views

Plugin Development: intercept Entry before returned to template

Is there a hook in Craft to intercept an Entry before being returned to a (front-end) template? Thinking here of ways we can manipulate what is being returned in the Element Criteria Model without ...
  • 1,741
1 vote
1 answer
250 views

Limit ElementAPI results with custom date/time field

What is the proper syntax in the ElementAPI 'criteria' configuration settings for limiting entries based on custom start and end date/time fields. I can't use the default postDate and expiryDate due ...
  • 123
2 votes
1 answer
157 views

ElementCriteriaModel UTF-8 Encoding

I have been working with data received from Guzzle and it is producing a Unicode String that looks similar to this Bachelor\u2019s Degree (after some parsing). When I save other content within craft ...
  • 123
2 votes
1 answer
730 views

Craft Commerce update variant field in plugin

I'm trying to get, update, and save products &/or variants in my plugin controller, and am stuck on accessing/changing/saving updated fields. // get product ID from post $variant_id = craft()->...
  • 1,118
2 votes
1 answer
71 views

Caching ElementCriteria Lookups In Craft CMS Plugins

Two recent sites I’ve built have plugins built to handle filtering through projects based on some categories and related entries. For example the lookups look similar to this: # Get element criterea ...
  • 917
4 votes
1 answer
450 views

multi-select OR values to filter entries

preface: i'm new to craft so may get terminology incorrect basic idea: i would like to show entries of a particular channel which have multi-select field values which intersect with another set of ...
  • 141
5 votes
1 answer
594 views

Get the type of action and the elements(s) that an action is being performed on when listening to elements.onPerformAction?

I have a plugin that needs to do something when an entry is deleted. I've recently discovered that the entries.deleteEntry event is not fired when deleting bulk entries (the list view with checkboxes) ...
  • 373
5 votes
1 answer
637 views

In the Element API plugin, how can I get only tags that are related to a particular section?

I tried to get all tags that are related to an section. Everything I tried failed. Is there a way to get all assigned tags for a particular element type by using element criteria model. In this case ...
2 votes
2 answers
112 views

Is it possible to use the MySQL LIKE directive in an ElementCriteriaModel?

In a plugin, I'd like to pull all Assets with filenames starting with a certain string (the $prefix variable, in the below examples). It's possible to do this with a custom DbCommand: $results = ...
1 vote
1 answer
74 views

Get latest assets added to structure

I have a structure which is basically categories of Downloads. In each Entry there is an "Files" field where multiple assets can be selected. On a Summary page I want to display the latest assets ...
  • 1,779
2 votes
1 answer
488 views

Element API "Last Updated Sections"

I am trying to create an endpoint that outputs the latest updated entry in each section (Themes, Videos and Screensavers) like this: url/updated.json { themes: '2016-08-22', videos: '2016-08-18', ...
3 votes
1 answer
152 views

Define elements that bust cache on save

I wrote a little plugin that reads some entries (Events) from my events section, orders them in a calendar-like structure and returns them to be displayed in a template. (I couldn't do this twig-only) ...
  • 383
2 votes
1 answer
373 views

Return element criteria model from attribute of a model

In one of my Plugin's CP templates I am using a element select field to grab elements from a custom element type. This field saves an array of element ids to a specific record's attribute called "...
  • 2,797
2 votes
1 answer
776 views

Query all categories once and get individual categories from array

I am working on a site that needs to both list all categories and also pull out individual categories by their id. I would like to query the DB once for all the categories (to improve performance), ...
  • 1,405
2 votes
1 answer
182 views

Sprout Forms -- How to link to individual entries on the front-end

I'm trying to build a front end to display entries collected through Sprout Forms. I want to create a list of all entry titles that can be clicked through to see the full entry. I can list a single ...
  • 1,000
3 votes
1 answer
81 views

A more economical method of building an archive menu?

I seem to be having trouble with the performance of my site (on localhost) after including this object. Im using it to build a menu for an archive of the posts section which has about 2,500 entries ...
  • 45
2 votes
1 answer
133 views

Filtering orders by date bring wrong results

I'm having a problem with wrong results when filtering order by date. I use this code: {% set orders = craft.commerce.orders.dateOrdered(' >= 2016-07-01 00:00:00').dateOrdered(' <= 2016-07-01 ...
2 votes
1 answer
75 views

"Natural" sorting for ElementCriteria

I want something sorted like this: MyString8 MyString9 MyString10 MyString11 $criteria->order = 'myField asc doesn't get things quite right, as MySQL has not native "natural sorting".
  • 3,071
3 votes
1 answer
819 views

Infinite getPrev and getNext?

I know how to display every next entry, but is it possible when there is no next entry it displays the first one and if there isn’t a previous display the last entry?
  • 36k
2 votes
1 answer
161 views

Is it possible to skip entries with children?

Hi I m using elementapi plugin to create an json object from my elements. I would like to get all entries, but not those ones who have a children. My criteria it looks like this now 'elementType' =&...
  • 143
3 votes
1 answer
810 views

How can I query for entries that have one of two Lightswitch fields enabled?

I have two Lightswitch fields – lightswitchA and lightswitchB – and I need to pull all entries in a certain section, that have one or both of these fields enabled. Is it possible to execute such a ...
1 vote
2 answers
1k views

Can I eager load Super Table fields in a Matrix block?

I have a Matrix with a Super Table in many of its blocks that I'm trying to eager load, but I can't figure out the syntax (or if its possible). The Super Table field's handle is columnSize and it ...
3 votes
3 answers
303 views

How do I order by _entry type_ when looping through entries in a template?

I currently have multiple sections like so: {% for craft.entries.section('mySection').type('oneType')... %} ... {% endfor %} {% for craft.entries.section('mySection').type('anotherType')... %} ....
  • 145
0 votes
2 answers
923 views

Criteria entries by date field

I want to get only entries with a specific date. I created a date field customDateField. It has the following code: {% set entries = craft.entries.section('orders').customDateField('2016-04-14') %} ...
1 vote
1 answer
608 views

Get entries by custom Users field value

There is a set of entries: {% set entries = craft.entries.section('news') %} Each entry has a custom field customUserField. customUserField this is a field Users. How do you fetch entries where ...
2 votes
1 answer
818 views

Eager-load and pagination

I'm currently working on a relation-heavy website with a colleague of mine and, for that reason, eager-loading stuff looks very appealing to us. We've succeeded in eager-loading pretty much everything ...
2 votes
1 answer
654 views

Excluding a single Entry ID of an Entry Type from craft.entries

Any help here would be appreciated… I feel like this is really close. I have 4 entry types, all of which are shown in a blog index: Article Video Image Blurb The most recent entry of the Article ...
1 vote
1 answer
1k views

Eager loading EntryElementType from custom ElementType in a plugin

trying to get my head wrapped around eager loading element relationships in my plugin. A little context, I’m working on a navigation module and I have a Node element type, which belongs to a ...
3 votes
1 answer
485 views

Querying for an exact match on a Matrix block field with multiple types

I'm trying to query against a specific field value in a Matrix field with multiple block types, and I've tried multiple approaches with no success. It either returns 0 results, or all blocks ...
  • 2,957
2 votes
2 answers
189 views

Are there any tradeoffs if you use the null-coalescing operator in place of first()?

With the addition of the null-coalescing operator (??) in Twig, it now appears that the following two examples both provide a way to retrieve the first entry and fallback to null if no entry exists: {...
  • 13.3k
7 votes
1 answer
1k views

Eager loading of reverse related elements?

Is it possible to load reverse related elements? I mean if the elements I’m querying are the target elements? Example: I’m setting up a criteria model to get some categories and I also want to load ...
  • 36k
3 votes
2 answers
321 views

Smart Map - Sorting for closest location in PHP

I want to sort entries with a Smart Map address field for closest location. I know how it should be done in a template: {% set entries = craft.entries.myAddress(params).order('distance').find() %} ...
2 votes
0 answers
83 views

Unable to get relatedTo working on an ElementCriteriaModel

In a plugin I am trying to get Users related to other Users: $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->group = 'partners'; $criteria->relatedTo = [ '...
  • 1,503
0 votes
1 answer
48 views

Display events that appear at certain venue

I'm trying to work out how to query some channel posts (events) that take place at a certain venue. {% set params = { section: 'events', } %} I have a 'eventVenue' field in my events section ...
  • 264