<p>When you use the <code>id</code> parameter (without the <code>not</code> directive), Craft will actually only return entries matching the IDs you pass in and nothing else, which means that both including and excluding a list of IDs in the same query is redundant.</p>

<p>Since you already have an array of IDs you want (<code>topViewedArticlesIds</code>) and an array of IDs you <em>don't</em> want (<code>presentArticles</code>), it's simply a matter of creating a third array of entry IDs that includes all the IDs in the former, without any of the IDs in the latter, and pass that in to <code>craft.entries</code>.</p>

<p>Fortunately, the <a href="https://craftcms.com/docs/templating/filters#without" rel="nofollow noreferrer"><code>without</code></a> filter makes this super-easy:</p>

<pre><code>{% set entryIds = topViewedArticlesIds|without(presentArticles) %}

{% set entries = craft.entries({
    section: 'articles',
    id: entryIds
}) %}
</code></pre>

<p>Note: If you want to make sure that the order of the returned entries is in the same order as the IDs in the <code>topViewedArticlesIds</code> array, you can pass in the <a href="https://craftcms.com/docs/templating/craft.entries#fixedOrder" rel="nofollow noreferrer"><code>fixedOrder</code></a> parameter:</p>

<pre><code>{% set entries = craft.entries({
    section: 'articles',
    id: entryIds,
    fixedOrder: true
}) %}
</code></pre>

CC BY-SA 3.0
2017-04-27T12:42:32.870Z
Wow awesome! Will give this a try!
mcclaskiem
CC BY-SA 3.0
2017-04-27T13:00:29.007Z
UPDATE: this works perfectly! Thank you!
mcclaskiem
CC BY-SA 3.0
2017-04-27T07:38:36.833Z
2017-04-27T07:38:36.833Z
Mats Mikkel Rummelhoff
<p>I am trying to get a query to work using the <code>id()</code> param on a <code>craft.entries.find()</code> call and am stuck getting nothing back from Craft.</p>

<p>We are getting an array of entry IDs from a CRM to personalize the content on the page which we then are fetching from Craft. At the same time we want to also omit certain IDs so we do not have duplicate entries on the same page.</p>

<pre><code>{% set entryQuery = 'and, ' ~ topViewedArticlesIds|join(',') ~ ',' ~ presentArticles|join(',not ') %}

{% set topViewed = craft.entries.find({
       section: 'articles',
       id: entryQuery
}) %}
</code></pre>

<p>I have used the id field before to omit certain entries but I have not combined them before so this may not even be possible in this via the <code>id</code> field.</p>

<p>Any help would be greatly appreciated!</p>

<entries><id>
ID query format
# ID query format

(Asked by: username_0 on 2017-04-26)

I am trying to get a query to work using the id() param on a craft.entries.find() call and am stuck getting nothing back from Craft.
We are getting an array of entry IDs from a CRM to personalize the content on the page which we then are fetching from Craft. At the same time we want to also omit certain IDs so we do not have duplicate entries on the same page.
{% set entryQuery = 'and, ' ~ topViewedArticlesIds|join(',') ~ ',' ~ presentArticles|join(',not ') %}

{% set topViewed = craft.entries.find({
       section: 'articles',
       id: entryQuery
}) %}

I have used the id field before to omit certain entries but I have not combined them before so this may not even be possible in this via the id field.
Any help would be greatly appreciated!

**Tags:** entries, id

---

## 1 answers

### Answer by username_1 on 2017-04-27. Score: 2 | Accepted answer

When you use the id parameter (without the not directive), Craft will actually only return entries matching the IDs you pass in and nothing else, which means that both including and excluding a list of IDs in the same query is redundant.
Since you already have an array of IDs you want (topViewedArticlesIds) and an array of IDs you don't want (presentArticles), it's simply a matter of creating a third array of entry IDs that includes all the IDs in the former, without any of the IDs in the latter, and pass that in to craft.entries.
Fortunately, the without filter makes this super-easy:
{% set entryIds = topViewedArticlesIds|without(presentArticles) %}

{% set entries = craft.entries({
    section: 'articles',
    id: entryIds
}) %}

Note: If you want to make sure that the order of the returned entries is in the same order as the IDs in the topViewedArticlesIds array, you can pass in the fixedOrder parameter:
{% set entries = craft.entries({
    section: 'articles',
    id: entryIds,
    fixedOrder: true
}) %}

> **Comments:**
> **username_0**: Wow awesome! Will give this a try!  
> **username_0**: UPDATE: this works perfectly! Thank you!  

---

