<p>If I understand correctly, you could do this in one query:</p>
<pre class="lang-twig prettyprint-override"><code>{% set vetCategoryID = 437950 %}

{# Get all entries where personnelType is empty OR equals vetCategoryID #}
{% set query  = craft.entries()
    .section('veterinarians')
    .personnelType([':empty:', vetCategoryID])
    .limit(10) %}

{# Paginate #}
{% paginate query as pageInfo, pageEntries %}

{% for entry in pageEntries %}
{{ entry.title }} &lt;br&gt;
{% endfor %}

{% if pageInfo.prevUrl %}&lt;a href=&quot;{{ pageInfo.prevUrl }}&quot;&gt;Previous Page&lt;/a&gt;{% endif %}
{% if pageInfo.nextUrl %}&lt;a href=&quot;{{ pageInfo.nextUrl }}&quot;&gt;Next Page&lt;/a&gt;{% endif %}
</code></pre>
<p>See documentation on <a href="https://craftcms.com/docs/3.x/categories-fields.html#querying-elements-with-categories-fields" rel="nofollow noreferrer">querying Categories fields</a> and <a href="https://craftcms.com/docs/3.x/dev/tags.html#paginate" rel="nofollow noreferrer">pagination</a>.</p>

CC BY-SA 4.0
2022-03-09T13:32:55.560Z
You're right, that's much better and won't need explanatory variable names. Thanks. Funny enough, I was reading that part of the doc and when I saw `:empty:` my brain went "Yea, that's all we need, no need to read anymore" :-D
InanisAtheos
CC BY-SA 4.0
2022-03-09T09:44:06.430Z
2022-03-09T09:44:06.430Z
Oli
<p>The answer to this was simpler than I thought. So simple, that I thought I had tried it already.</p>
<pre><code>{% set entries          = craft.entries.id(merged) %}

    {% for entry in entries %}
        {{ entry.id }}: {{ entry.title }}
    {% endfor %}
</code></pre>

CC BY-SA 4.0
2022-03-09T09:43:08.230Z
2022-03-09T09:43:08.230Z
InanisAtheos
<p>I have 2 arrays of entry ID's that I need to merge and generate an entries object that I can iterate through and paginate. The reason for doing it this way at all, is that I need to display entries with a specific category, and those without any category as per the code below.</p>
<p>Perhaps I'm approaching this all wrong and there's a different way to get the entries.</p>
<pre><code>{% set vetCategoryID        = 437950 %}
    {% set noPersonnelType  = craft.entries.section('veterinarians').personnelType(':empty:').limit(null).ids() %}
    {% set vets             = craft.entries.section('veterinarians').personnelType(vetCategoryID).limit(null).ids() %}
    {% set merged           = noPersonnelType|merge(vets) %}
    
    {# this displays all, but makes pagination impossible, so no dice. #}
    {% for item in merged %}
        {% set entry = craft.entries({id: item}) %}
        {{ dd(entry) }}
    {% endfor %}
</code></pre>
<p>I tried using <code>{% set entries = craft.entries(merged) %}</code> but that doesn't work at all.</p>
<p>Searching here gives me this question: <a href="https://craftcms.stackexchange.com/questions/17155/converting-array-of-entries-to-an-array-of-ids">Converting array of entries to an array of ids</a>, but it's the opposite problem.</p>

<templating><entries>
Construct entries object from an array of IDs
# Construct entries object from an array of IDs

(Asked by: username_0 on 2022-03-09)

I have 2 arrays of entry ID's that I need to merge and generate an entries object that I can iterate through and paginate. The reason for doing it this way at all, is that I need to display entries with a specific category, and those without any category as per the code below.
Perhaps I'm approaching this all wrong and there's a different way to get the entries.
{% set vetCategoryID        = 437950 %}
    {% set noPersonnelType  = craft.entries.section('veterinarians').personnelType(':empty:').limit(null).ids() %}
    {% set vets             = craft.entries.section('veterinarians').personnelType(vetCategoryID).limit(null).ids() %}
    {% set merged           = noPersonnelType|merge(vets) %}
    
    {# this displays all, but makes pagination impossible, so no dice. #}
    {% for item in merged %}
        {% set entry = craft.entries({id: item}) %}
        {{ dd(entry) }}
    {% endfor %}

I tried using {% set entries = craft.entries(merged) %} but that doesn't work at all.
Searching here gives me this question: Converting array of entries to an array of ids, but it's the opposite problem.

**Tags:** templating, entries

---

## 2 answers

### Answer by username_1 on 2022-03-09. Score: 3 | Accepted answer

If I understand correctly, you could do this in one query:
{% set vetCategoryID = 437950 %}

{# Get all entries where personnelType is empty OR equals vetCategoryID #}
{% set query  = craft.entries()
    .section('veterinarians')
    .personnelType([':empty:', vetCategoryID])
    .limit(10) %}

{# Paginate #}
{% paginate query as pageInfo, pageEntries %}

{% for entry in pageEntries %}
{{ entry.title }} 
{% endfor %}

{% if pageInfo.prevUrl %}Previous Page{% endif %}
{% if pageInfo.nextUrl %}Next Page{% endif %}

See documentation on querying Categories fields and pagination.

> **Comments:**
> **username_0**: You're right, that's much better and won't need explanatory variable names. Thanks. Funny enough, I was reading that part of the doc and when I saw `:empty:` my brain went "Yea, that's all we need, no need to read anymore" :-D  

---

### Answer by username_0 on 2022-03-09. Score: 1

The answer to this was simpler than I thought. So simple, that I thought I had tried it already.
{% set entries          = craft.entries.id(merged) %}

    {% for entry in entries %}
        {{ entry.id }}: {{ entry.title }}
    {% endfor %}


---

