<p>You answered your own question, you just need a list of IDs to exclude rather than a single ID.</p>
<p>Here's an example in which the incoming IDs are <a href="https://twig.symfony.com/doc/3.x/filters/split.html" rel="nofollow noreferrer">split</a> and <a href="https://twig.symfony.com/doc/3.x/filters/merge.html" rel="nofollow noreferrer">merged</a> into the <a href="https://craftcms.com/docs/4.x/entries.html#id" rel="nofollow noreferrer">id</a> query parameter to filter out the entry IDs.</p>
<p>The <a href="https://twig.symfony.com/doc/3.x/filters/join.html" rel="nofollow noreferrer">join</a> filter is then used to output the merged last IDs with the IDs from the query.</p>
<pre><code>{% set lastEntryIds = lastEntryIds ?? '' %}
{% set lastEntryIds = lastEntryIds|split(',') %}

{% set query = craft.entries()
    .section(section)
    .id(['not']|merge(lastEntryIds)
    .orderby('RAND()')
    .offset(offset)
    .limit(3) 
%}

{% set items = query.all() %}
{% set ids = query.ids() %}

{{ hiddenInput('lastEntryIds', lastEntryIds|merge(ids)|join(',')) }}
</code></pre>

CC BY-SA 4.0
2023-02-19T15:01:01.170Z
2023-02-19T15:01:01.170Z
Ben Croker
<p>On an article page i show 3 random entries, and a load more button via sprig.</p>
<pre><code>{% set query = craft.entries().section(section).orderby('RAND()').offset(offset).limit(3) %}

{% set items = query.all() %}
</code></pre>
<p>Pressing the load more button shows 3 more Entries.</p>
<p>Now i get duplicate entries. How can i prevent this and exclude the already shown
entries?</p>
<p>As described <a href="https://putyourlightson.com/sprig/videos#1-introduction-to-sprigcart" rel="nofollow noreferrer">here in video 2</a> in the sprig documentation, if i have only one random article and want to
reload the component and show another random article, i can exclude the last shown entry in the query.</p>
<p>set a last entry id:</p>
<pre><code>{% set lastEntryId = lastEntryId ?? 0 %}
</code></pre>
<p>in the link/button to get the next random entry, set the value:</p>
<pre><code>s-val:last-entry-id=&quot;{{ entry.id }}&quot;
</code></pre>
<p>and in the query i exclude the last used id:</p>
<pre><code>{% set query = craft.entries().section(section).id('not ' ~ lastEntryId).orderby('RAND()').offset(offset).limit(3) %}
</code></pre>
<p>How can i adopt this to my setup?
I guess, get the already 3 first shown entries and put them in array and exclude these ids in the query (how do i do that?) and update this array after showing more entries with the load more button.</p>

<entries><plugin-sprig><random>
Sprig load more: prevent repeating entries with random output
# Sprig load more: prevent repeating entries with random output

(Asked by: username_0 on 2022-06-14)

On an article page i show 3 random entries, and a load more button via sprig.
{% set query = craft.entries().section(section).orderby('RAND()').offset(offset).limit(3) %}

{% set items = query.all() %}

Pressing the load more button shows 3 more Entries.
Now i get duplicate entries. How can i prevent this and exclude the already shown
entries?
As described here in video 2 in the sprig documentation, if i have only one random article and want to
reload the component and show another random article, i can exclude the last shown entry in the query.
set a last entry id:
{% set lastEntryId = lastEntryId ?? 0 %}

in the link/button to get the next random entry, set the value:
s-val:last-entry-id="{{ entry.id }}"

and in the query i exclude the last used id:
{% set query = craft.entries().section(section).id('not ' ~ lastEntryId).orderby('RAND()').offset(offset).limit(3) %}

How can i adopt this to my setup?
I guess, get the already 3 first shown entries and put them in array and exclude these ids in the query (how do i do that?) and update this array after showing more entries with the load more button.

**Tags:** entries, plugin-sprig, random


---

## 1 answers

### Answer by username_1 on 2023-02-19. Score: 1

You answered your own question, you just need a list of IDs to exclude rather than a single ID.
Here's an example in which the incoming IDs are split and merged into the id query parameter to filter out the entry IDs.
The join filter is then used to output the merged last IDs with the IDs from the query.
{% set lastEntryIds = lastEntryIds ?? '' %}
{% set lastEntryIds = lastEntryIds|split(',') %}

{% set query = craft.entries()
    .section(section)
    .id(['not']|merge(lastEntryIds)
    .orderby('RAND()')
    .offset(offset)
    .limit(3) 
%}

{% set items = query.all() %}
{% set ids = query.ids() %}

{{ hiddenInput('lastEntryIds', lastEntryIds|merge(ids)|join(',')) }}


---

