Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-19T15:01:01.170Z
Answers.LastActivityDate: 2023-02-19T15:01:01.170Z
Answers.UserDisplayName: Ben Croker
Body: <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>
  
Tags: <entries><plugin-sprig><random>
Title: Sprig load more: prevent repeating entries with random output
ThreadText: # 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](https://putyourlightson.com/sprig/videos#1-introduction-to-sprigcart) 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](https://twig.symfony.com/doc/3.x/filters/split.html) and [merged](https://twig.symfony.com/doc/3.x/filters/merge.html) into the [id](https://craftcms.com/docs/4.x/entries.html#id) query parameter to filter out the entry IDs.
  
  The [join](https://twig.symfony.com/doc/3.x/filters/join.html) 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(',')) }}
  
  ```
  
  
  ---
  
  