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
4 votes
1 answer
1k views

Complex logic on a ElementCriteriaModel parameter?

How would you combine multiple logical expressions on a ElementCriteriaModel parameter? You could query twice and then merge the two returned arrays of entry models, but that probably wouldn't allow ...
  • 36k
12 votes
2 answers
1k views

What are the differences between an elementCriteriaModel and fetched elements?

I am a little confused about the differences between an elementCriteriaModel and fetched elements. Why do I sometimes have to fetch elements with first(), last(), find(): {% set entries = craft....
  • 8,346
22 votes
3 answers
4k views

How can I get only those entries with non-empty assets field

Since Craft 2.0 it is possible to pass :empty: and :notempty: to ElementCriteriaModel parameters when you’re looking for empty/non-empty values. If you are for example looking for all entries with a ...
  • 36k
7 votes
1 answer
1k views

How can I do more complicated queries with an ElementCriteriaModel?

I need to join my 3rd party table with a standard ElementCriteriaModel (ECM). I'd like to start with an ordinary ECM, so my plugin will be compatible with any element type which may exist, now or in ...
  • 23.8k
5 votes
1 answer
1k views

How can I create an ElementCriteriaModel with 'and' and 'or'

In my template, I want to: Get all the entries in the section 'uploads'; Get all the assets that are related to one of the upload entries, and have a relation to all the tags I provide. So, that ...
  • 6,318
12 votes
2 answers
1k views

How to find entries with no category

I have a field categories in a channel news, and I want to find all the entries in news that don't have a category set. I know I could loop over the entries and find them that way, but I'm hoping to ...
5 votes
1 answer
1k views

How do I get elements using getCriteria from a specific date?

I'm trying to get elements in a section created on a specific date. How do I do that? This is what I've been trying with: $criteria = craft()->elements->getCriteria(ElementType::...
  • 2,834
4 votes
1 answer
915 views

How can I output a list of categories that are not empty?

In other words, categories must have at least one enabled entry assigned to them.
  • 1,503
4 votes
2 answers
479 views

What's the difference between ElementCriteriaModel and DbCommand?

Forgive me if this is a stupid or naive question... I generally think of an ElementCriteriaModel as being a "search object". Specifically, it's a search object which revolves around a specific type ...
  • 23.8k
15 votes
1 answer
1k views

How do you sort elements queried from multiple channels?

This is how I query elements from multiple channels: {% set allEntries = craft.entries.section(['publication','text', 'exhibition']).limit(null) %} I now want to sort all these entries by a custom ...
  • 36k
6 votes
1 answer
675 views

How can I return specific matrix rows based on criteria?

So let's say I have the following code. I have the data to retrieve the entry I want, But I only want to return some of the matrix rows based on some criteria. Example Code: {% set entryId = 1 %} {% ...
6 votes
1 answer
901 views

Get related entry data within a plugin (ElementCriteriaModel) without extra queries

I have the following code: $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'submissions'; // Loop foreach ($criteria as $entry) { echo $entry->id....
5 votes
2 answers
1k views

How to retrieve entries from two entry-types ordered by different date-fields?

I have two entry-types, 'Events' and 'Reports'. 'Events' have a matrix-field ('eventMultiDate') that allows authors to assign multiple dates to an event (recurring). 'Reports' have the default '...
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
732 views

How can you return elements between two values?

I my be in a bit of a "wood for the trees" situation but how is it possible to return elements based on a custom field being between two supplied values. For example returning users based on a number ...
3 votes
1 answer
671 views

How to fetch specific users OR admins with the ElementCriteriaModel?

I'm getting all Users from specific UserGroups like this: $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->groupId = array(1, 3); $users = $criteria->find(); But ...
  • 8,346
2 votes
1 answer
368 views

Is there a way to return asset data along with entry data?

I'm using the Element API plugin to return data from an entry that also contains an image asset. Is there a way to combine the two so I can get the asset URL alongside the entry fields? Attached ...
  • 21
2 votes
1 answer
508 views

Can someone help me identify why my entry is invalidating?

I have a custom plugin that's saving an entry successfully. While saving the entry I'm setting our "merchant" field (an entries field, limit=1) like so: <?php # ... $entry = newEntryModel(); # set ...
2 votes
1 answer
223 views

Missing Matrix row types on output after upgrade to Craft 3 (subsetting and cloning ElementQueries)

Update: Now I know the cause of my problem, I have appended to the original question title to try and help other people stumbling across the same issue. I have a pending support ticket open with P&...
6 votes
2 answers
707 views

Ability to SUM() or GROUP BY from the template or ElementCriteriaModel

After twitter conversation with Brandon Kelly, is it possible to implement something similar to the following? craft.entries.section("mySection").sum("myCustomField")
6 votes
1 answer
1k views

How can I follow relations in ElementCriteriaModels from plugin code?

In Twig code you can use craft->entries->relatedTo to do all sorts of neat things. From plugin code I am not sure how this works? $c = craft()->elements->getCriteria(ElementType::Entry)...
  • 631
6 votes
1 answer
517 views

Display thumbnail using defineTableAttributes for a custom Element Type

Hi, I'm new to Craft and VERY new to plugin development. I'd like to display a thumbnail image in my table list view and thought it would be possible to accomplish using a new Custom Element Type. ...
  • 121
5 votes
3 answers
775 views

Template Hook + Caching

A portion of my template is being cached, using the standard cache tag: {% cache %} Within that cached section of the template, I'm using a template hook: {% hook 'myTemplateHook' %} Within that ...
  • 23.8k
4 votes
1 answer
690 views

Modify ElementCriteria and use it for paginate

First some context. I'm using Smart Map for Craft to display some location based events in a listing. My structure is as follows: Events channel Locations channel Each event can occur multiple times,...
  • 137
4 votes
1 answer
1k views

Build Query relatedTo multiple categories

Trying to build a complex query and I'm sure there is bound to be a better way of doing it that the multiple if statements I currently have. URL for the page is /products/(category1)/(category2)/(...
  • 1,779
4 votes
1 answer
448 views

How to create a query to group alternate language pages?

I'm trying to create a sitemap for a site with multiple locales. An example of the format is described here, but as a quick summary: I need to output locales of related translated pages aside one ...
  • 13.3k
4 votes
1 answer
288 views

Get entries that's not already listed

I have a bunch of entries in a section called 'artikkel'. The 14 first of these entries are listed out in another section called 'forside'. Now I need to list out the entries that's not already been ...
  • 105
3 votes
1 answer
917 views

Add custom element criteria attribute without a field type?

Is a custom field type and making use of modifyElementsQuery the only way to add my own craft.entries element criteria model attribute to modify the elements query? What if I do not want to add a new ...
  • 36k
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 ...
3 votes
1 answer
694 views

Filtering Matrix through field value and multiple relations

I've the following situation: Accommodations (entry) title description (textfield) ... linkedTo (matrix block) Sport (category) targetGroup (category) minimumAge (number) maximumAge (number) What ...
  • 33
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
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
2 votes
1 answer
769 views

Searching for entries across multiple fields including a relationship

I'm trying to fetch a set of entries based on search parameters. The search is an "and" search, meaning that if criteria exist then they should all match for there to be a result returned. I have ...
  • 2,009
2 votes
1 answer
490 views

How to return entries based on Checkboxes field criteria?

Ok I'm building a plugin that needs to check for an id in an array and return only users that have the id in the checkbox array. So this is what I have: $user_criteria = craft()->elements->...
  • 2,033
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 ...
1 vote
1 answer
506 views

Returning ElementCriteriaModel of entries via plugin

I'm outputting an element criteria model in a Craft 2 plugin of some entries in a channel. I noticed that when I fetch the entries the standard template way {% set entries = craft.entries.section('...
  • 1,942
1 vote
2 answers
786 views

Use getCriteria with OR condition on multiple fields

I am filtering users in my CP by adding a new user source. I know how to get users for specific criterias. But in this case I want to make a OR condition on those two users fields : $user_criteria-&...
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 ...