<p>You can build an array of the filtered results, then paginate that.</p>

<pre><code>{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set filteredEntries = [] %}
{% set existingtitle = [] %}
{% for entry in entries %}
    {% if entry.title not in existingtitle %}
        {% set filteredEntries = filteredEntries|merge([entry]) %}
    {% endif %}
    {% set existingtitle = existingtitle|merge([entry.title]) %}
{% endfor %}
</code></pre>

<p>Then modify this code to paginate array: <a href="https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a" rel="nofollow noreferrer">https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a</a></p>

CC BY-SA 4.0
2019-08-22T07:09:40.123Z
This gives me the error message: **TypeError: Argument 1 passed to craft\helpers\Template::paginateCriteria() must implement interface yii\db\QueryInterface, array given, ...**
TomS
CC BY-SA 4.0
2019-08-22T08:42:17.110Z
My mistake, I thought you could paginate arrays. This tweet might be helpful to you: https://twitter.com/juban/status/1139207162159386625
dmatthams
CC BY-SA 4.0
2019-08-22T08:45:19.383Z
Even better, a gist: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a have updated answer to reflect
dmatthams
CC BY-SA 4.0
2019-08-22T12:33:13.057Z
Thank you very much! I'll try this
TomS
CC BY-SA 4.0
2019-08-23T08:07:59.820Z
I could solve it, with this code: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a, thanks a lot to user3788089 for this information!
TomS
CC BY-SA 4.0
2019-08-21T11:00:23.827Z
2019-08-22T08:44:59.927Z
2019-08-22T08:44:59.927Z
dmatthams
<p>Some of my entries have the same entry.title. At the frontend, I would like to display these entries only once. This works with the following code:</p>

<pre><code>{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set existingtitle = [] %}
 {% for entry in entries %}
  {% if entry.title not in existingtitle %}        
    {{ Display the Results }}
  {% endif %}
  {% set existingtitle = existingtitle|merge([entry.title]) %}
 {% endfor %}
</code></pre>

<p>My question is: How can I then paginate these results? For example 9 entries per page?
If I paginate before the "if" condition gives me not the required result.
Any help or tips are highly appreciated!</p>

CC BY-SA 4.0
2019-08-09T18:00:01.580Z
For issue 1 you could create another query on your second page using the offset function. So .limit(1).offer(8). This should get you the 9th entry. Also I would consider looping through your returned data and maybe reordering into a new array with the title as a key maybe.
Dean Sanderson
<entries><pagination><merge>
Pagination and "if" condition
# Pagination and "if" condition

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

Some of my entries have the same entry.title. At the frontend, I would like to display these entries only once. This works with the following code:
{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set existingtitle = [] %}
 {% for entry in entries %}
  {% if entry.title not in existingtitle %}        
    {{ Display the Results }}
  {% endif %}
  {% set existingtitle = existingtitle|merge([entry.title]) %}
 {% endfor %}

My question is: How can I then paginate these results? For example 9 entries per page?
If I paginate before the "if" condition gives me not the required result.
Any help or tips are highly appreciated!

**Tags:** entries, pagination, merge
> **Comments:**
> **username_1**: For issue 1 you could create another query on your second page using the offset function. So .limit(1).offer(8). This should get you the 9th entry. Also I would consider looping through your returned data and maybe reordering into a new array with the title as a key maybe.  

---

## 1 answers

### Answer by username_2 on 2019-08-21. Score: 2 | Accepted answer

You can build an array of the filtered results, then paginate that.
{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set filteredEntries = [] %}
{% set existingtitle = [] %}
{% for entry in entries %}
    {% if entry.title not in existingtitle %}
        {% set filteredEntries = filteredEntries|merge([entry]) %}
    {% endif %}
    {% set existingtitle = existingtitle|merge([entry.title]) %}
{% endfor %}

Then modify this code to paginate array: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a

> **Comments:**
> **username_0**: This gives me the error message: **TypeError: Argument 1 passed to craft\helpers\Template::paginateCriteria() must implement interface yii\db\QueryInterface, array given, ...**  
> **username_2**: My mistake, I thought you could paginate arrays. This tweet might be helpful to you: https://twitter.com/juban/status/1139207162159386625  
> **username_2**: Even better, a gist: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a have updated answer to reflect  
> **username_0**: Thank you very much! I'll try this  
> **username_0**: I could solve it, with this code: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a, thanks a lot to user3788089 for this information!  

---

