Get random entries, excluding an array of entry IDs, where a relational field is not empty 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?
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.