<p>I think you're correct in how you currently do it. You can't merge Element Queries, you can merge IDs (or any array of anything, really). 
The only thing you should remove, is the <code>all</code> when settings <code>posts</code>, because <code>paginate</code> expects an element query, not an array of elements. </p>

CC BY-SA 4.0
2019-05-09T15:08:39.037Z
You are correct! I didn't test the code before posting so I'll go ahead and edit that.
Matthew Rotter
CC BY-SA 4.0
2019-05-09T15:15:38.053Z
I just wasn't sure if there was some sexy way to combine both queries into a single line instead
Matthew Rotter
CC BY-SA 4.0
2019-05-09T15:20:48.940Z
I don’t think there’s a way to combine relatedTo with a custom field condition and achieve what you want to achieve.
Paul
CC BY-SA 4.0
2019-05-09T15:01:51.807Z
2019-05-09T15:01:51.807Z
Paul
<p>Here's how I'd do it currently: </p>

<pre><code>{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]).ids() %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1').ids() %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% set posts = craft.entries.id( allEntries ) %}

{% paginate posts.limit(12) as pageInfo, pet %}
</code></pre>

CC BY-SA 4.0
2019-05-09T14:52:01.303Z
2019-05-09T15:09:00.720Z
2019-05-09T15:09:00.720Z
Matthew Rotter
<p>I really want something like this to work but the merge function turns Elements into Arrays. I've managed to work around it other times but what's the best practice to combine two entry sets and then paginate?</p>

<pre><code>{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]) %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1') %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% paginate allEntries.limit(12) as pageInfo, pet %}
</code></pre>

<entries><pagination><merge>
Paginating Merged Element Queries
# Paginating Merged Element Queries

(Asked by: username_0 on 2019-05-09)

I really want something like this to work but the merge function turns Elements into Arrays. I've managed to work around it other times but what's the best practice to combine two entry sets and then paginate?
{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]) %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1') %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% paginate allEntries.limit(12) as pageInfo, pet %}

**Tags:** entries, pagination, merge


---

## 2 answers

### Answer by username_1 on 2019-05-09. Score: 2

I think you're correct in how you currently do it. You can't merge Element Queries, you can merge IDs (or any array of anything, really).
The only thing you should remove, is the `all` when settings `posts`, because `paginate` expects an element query, not an array of elements.

> **Comments:**
> **username_0**: You are correct! I didn't test the code before posting so I'll go ahead and edit that.  
> **username_0**: I just wasn't sure if there was some sexy way to combine both queries into a single line instead  
> **username_1**: I don’t think there’s a way to combine relatedTo with a custom field condition and achieve what you want to achieve.  

---

### Answer by username_0 on 2019-05-09. Score: 2

Here's how I'd do it currently: 
{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]).ids() %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1').ids() %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% set posts = craft.entries.id( allEntries ) %}

{% paginate posts.limit(12) as pageInfo, pet %}


---

