4

I'm trying to pull a set of 3 random entries from a Section. The entries need to have a certain Assets field not empty, and I also have to exclude entries already pulled (these entries are stored in the variable entriesA).

The issue is that with my current query, the ID exclusion doesn't work – i.e. I'm getting back entries found in entriesA.

Here's how the query looks:

{% set entriesB = craft.entries({
    section : 'someSection',
    assetsField : ':notempty:',
    limit : 3,
    order : 'RAND()',
    id : 'and, not ' ~ entriesA.ids()|join(', not ')
}) %}

The problem appears to be the assetsField : ':notempty:' statement – when I remove that, I get no duplicates. When it's included, Craft appears to ignore the id parameter and I get back duplicates.

Anyone know what's up? Is it not possible to query using :notempty: statements and id?

4

That seems to be a bug / limitation of the :notempty: statement, it's probably adding its own ID criteria in the background and the merge doesn't work as expected. I'd suggest you file a bug report.

In the meantime you could just add the "not empty asset field" criteria making use of the relatedTo parameter as a workaround. See How can I get only those entries with non-empty assets field for example code.

  • Excellent Carl, thanks. I guess I have to bite the bullet and use relatedTo on this one :) – Mats Mikkel Rummelhoff Mar 31 '16 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.