Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

1
vote
1answer
16 views

Pagination and Entry Model on Homepage

On my site I have some entries with images. In the entry template I paginate the images like so: {% paginate entry.images.limit(1) as images %} My homepage is a single random entry and I want to ...
1
vote
0answers
7 views

Plugin, getting an entry when one of multiple category fields and/or lightswitches are not empty/turned on

Basically I’m trying to get en Entry where, either one (or more) of three lightswitches is (are) turned on, or where either categoryOne or categoryTwo is not empty. This is what I got so far, but it ...
1
vote
1answer
21 views

Element criteria with a table field

I am trying to build a query to fetch some entries which I want filter on a table field between multiple values. The table field is "filterTestWidth" and has 1 col named "size" (number type). There ...
0
votes
0answers
7 views

ElementIndex hangs on elements.onBeforeBuildElementsQuery

I am trying to modify the ElementCriteriaModel from my plugin when loading the elementIndex on /entries of the control panel. My plugin consists of some access-restricting code to block access to ...
1
vote
0answers
15 views

Get Entries with a specified. Custom FieldType

I have created a Custom FieldType with AttributeType::Mixed The field actually saves the a Custom Model I created. I'm trying to retrieve all the entries that have my custom model as the field. I'm ...
0
votes
1answer
30 views

Impossible to access an attribute (“url”) on a null variable in search results

I have a search results page set up like this: {% set searchResults = craft.entries(queryParams) %} {% paginate searchResults as pageInfo, pageEntries %} {% if pageEntries|length %} {% for yacht ...
1
vote
1answer
16 views

Get the fields (fieldLayout) of the section. Not the entry

Can I get all the fields of a section? For example, I have channel events, I want the fields in that section, but not related to any specific event. I want to know all the fields (not the values), ...
1
vote
0answers
38 views

Element API plugin: searching and working with nested objects

I’m experimenting with the Element API plugin and working with querying the tags of the assets that appear in matrix blocks in a set of entries. Essentially I’m hoping to be able to use a tag in a ...
1
vote
1answer
42 views

How to create an element query in PHP with custom field names in variables?

I'm trying to dynamically create an element query in PHP where the custom field criteria come from an array of strings. Something like this...? $users = User::find(); $users->group($groupList); ...
0
votes
0answers
19 views

Getting total results count (and/or using pagination) after ElementCriteriaModel is converted to dbCommand via buildElementsQuery

I've implemented a custom search plugin that generates an ElementCriteriaModel, converts it via buildElementsQuery and then adds additional SQL SELECTs (for geo searching over latitude/longitude ...
0
votes
1answer
36 views

Get all entries with linked entry in entries field

I have a channel called 'projects'. This channel has two entries fields: relatedThemes relatedAreas What I want to do is perform a search query which filters all projects where the relatedThemes ...
1
vote
1answer
16 views

Not showing the entry somewhere else on the same page

In the footer there is a column showing the images of the most recent entries. How do you prevent the image from the main entry itself to be shown? Do you test an url segment against the title or ...
2
votes
1answer
51 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&...
1
vote
1answer
21 views

Error using assets operations

I am having trouble getting images by name. craft.assets.first() function in assets gives the proper output of one image. But when I try craft.assets.filename('flag.jpg'), craft shows the following ...
1
vote
1answer
41 views

How to get related entry data using ElementCriteriaModel in a plugin

I am working on a custom plugin which gets some entry data using $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->order('postDate asc'); $criteria->dateUpdated = ...
1
vote
1answer
32 views

How to limit navigation by entry type

I couldn't find this anywhere so I thought I would post the answer. How do you limit the output of a navigation element to a specific entry type. This question is explicitly for the navigation ...
1
vote
1answer
84 views

How to build complex Element Criteria?

How to fetch Elements with a complex DB query? E.g. with some nested AND/OR conditions or just apply two conditions to one field? For example my Elements have a field eventDate. I want to fetch all ...
1
vote
1answer
87 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('...
2
votes
1answer
65 views

Search for entries where a field value is between multiple ranges of numbers

I currently have this working for a single range of numbers, but I can’t figure it out for multiple ranges. I currently have it set up like this for one range, and it works. myFieldHandle: ['and', '&...
1
vote
1answer
67 views

How can I iterate through my entries?

I want to iterate through my entries on the click of a 'next' and 'previous' button. I have started off using getNext() and getPrev() by I'm in a bit of a rut. {% set entry = craft.entries.section('...
1
vote
2answers
41 views

Getting a single, random, related entry within a plug in

Given a Matrix with each row containing a text field and a multi relationship field. And I am picking 1 Matrix row based on the value in the text field. How would I go about selecting a single, random,...
1
vote
2answers
106 views

Retrieve entries on custom field date using ElementCriteriaModel

I am trying to retrieve an array of entries on a particular section where inspectionDate is greater than today's date. Here is the code. $criteria = craft()->elements->getCriteria(ElementType::...
1
vote
0answers
54 views

Using target element criteria to filter results

I'm using the Element API plugin to try and search for addresses using minimum and maximum lat & lng values and then using target element within the criteria parameters to filter the results ...
0
votes
0answers
52 views

If an entry doesn't exist in a locale and returns a 404, how can I check if the entry exists in a different locale?

I'm trying to create a mechanism for informing users that a particular entry is not available in the selected language, and providing a link to read the article in an alternative language. Therefore, ...
1
vote
1answer
44 views

Load more images in matrix block

I have a matrix block called team that has an assets field within it that has all of the companies headshots. However, there are more than 30 images, but the design is to only have 6 showing on load, ...
1
vote
1answer
91 views

ElementCriteriaModel andWhere() with different comparison operators?

I'm trying to do an andWhere() "OR" group for a special criteria value so basically when building an element criteria I want to just set `$criteria->upcomingOnly to true, and then have the following ...
1
vote
1answer
63 views

getting the current user entries from elementapi

How do I use the elementapi to get the list of entries for the logged in user? I've tried a couple of options to no avail, like 'api/v1/user/<userId:\d+>.json' => function($userId) { ...
0
votes
2answers
63 views

Exclude entries by array of authors from ElementCriteriaModel

I'm trying to get a list of entries of a certain section, however I'd like to exclude certain users that are defined within a field of the entry. The users to exclude from the query are fetched like ...
0
votes
0answers
37 views

For-loop inside for-loop to access Matrix fields, more efficient solution?

I'm currently building a template that needs to output several Matrix-field entries and afterwards loop through another section to look for a specific entry, depending on the id the Matrix-field ...
3
votes
1answer
131 views

How to pull entries with Date Created > start and < end?

I'm building an export plugin in Craft 2 and the entries are saved by the front-end and are never enabled, so no Post Date. I have a form with the forms.date selectors that sends a start and end date ...
1
vote
0answers
30 views

Save or efficiently query a count from a related table

I have two custom element types, Event and Booking. They are related via the eventId column on the Booking record which is a FK to the Event record. The Booking record also has a seats column. A ...
1
vote
1answer
328 views

Element Criteria Model: filtering by empty values

I'm trying to use the Element Criteria Model to retrieve all entries where value X or value Y is not null? I can get all entries where values and X and Y are not empty but not sure how to achieve ...
4
votes
1answer
92 views

How do I query two relationship fields where one relationship MUST be empty?

I have two relationship fields. I am trying to query all entries where the first field is related to a particular element and the second field is related to nothing. Here is how I thought it would ...
1
vote
1answer
80 views

How to display a specific image from Assets field

I have an Assets field with a set of images. What is the best way to find one image that has 'featured' checkbox checked? This is the code I put together to check which of the images is marked '...
1
vote
1answer
70 views

craft.matrixBlocks element queries with .type()

I'm using Craft Pro 3.0.0-beta.19 and I try to query matrix blocks with craft.matrixBlocks(). Background: I have event series (=structure) with a matrix block containing 1:n dates for each series. My ...
1
vote
1answer
29 views

Trouble with buildElementQuery customization

I’m having a problem modifying an ElementCriteria with buildElementsQuery. The results elements totally mixes locale results. I can only get english URL for example. Here is a gist of my code. https:/...
1
vote
0answers
113 views

Craft 3 improvements to relationship querying?

I've been using Craft for a couple of years now and I do love it, however I consistently run into massive performance issues with it. I heavily rely on caching and eager loading - however this doesn't ...
3
votes
1answer
53 views

How can I get entries where a date is within a dynamic date range?

{% set params = { section : 'events', order : 'eventStartDate asc', eventStartDate : '>=' ~ now, limit : row.itemsPerPage.value } %} I am trying to pull a set of event ...
1
vote
1answer
87 views

no element type exists with getCriteria and custom element type

I am working on a plugin using the getCriteria function, but for every Element Type I put, I always get an error: No element type exists by the type “Comerce_Group”. $criteria = craft()->...
4
votes
1answer
70 views

Store categories in array by level in controller

I'm making a plugin and I need to get an array from a certain category group where the levels of the array are the same as the level of the categories in the group. So I used the following code to ...
1
vote
1answer
124 views

entries.saveEntry not triggered by ResaveElements task

I've got a plugin that does a thing when an entry is resaved. It works great. However I need it to fire for every single entry to build some data. craft()->on('entries.saveEntry', function(Event $...
1
vote
1answer
32 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
0answers
37 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
0answers
45 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 ...
1
vote
1answer
64 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
1answer
377 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
1answer
38 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 ...
2
votes
2answers
259 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
0answers
96 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'] }] ] }) %} ...
2
votes
1answer
114 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'] }] ] }) %} ...