<p>Based on the example you linked: You can prevent duplicate entries by explicitly excluding the entries you've already seen using the <a href="https://craftcms.com/docs/3.x/entries.html#id" rel="nofollow noreferrer"><code>id</code> method</a>. Since you already have an array of IDs you have already displayed  (<code>existingIds</code>), you only need to prepend 'not' to negate the query and exclude those entries:</p>
<p><a href="https://craftcms.com/docs/3.x/entries.html#id" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/entries.html#id</a></p>
<pre><code>{% set featuredArticle = craft.entries
    .section('articles')
    .id(['not']|merge(existingIds))
    .one() %}
</code></pre>
<p>This will ensure you always get an entry you haven't displayed before. This also allows you to get rid of the <code>offset()</code>.</p>
<hr />
<p>Sidenote: I'm using <code>one()</code> instead of <code>all()</code> to execute the query. This returns only a single entry instead of an array of entries, so you can remove the <code>limit(1)</code> call as well. It also allows you to get rid of the loop, since the result is a single entry instead of an array of entries.</p>

CC BY-SA 4.0
2021-08-10T08:22:51.507Z
Amazing! I find out how to use slice as well so now featured section looks like this: https://pastecode.io/s/tbmh68a0. I added id method to lower column since I don't want any of featured content to be display in it and it looks like this: https://pastecode.io/s/psqtax01 Is it correct way to implement everything?
Lukas Snarskis
CC BY-SA 4.0
2021-08-10T08:33:17.617Z
@LukasSnarskis Looks good to me! If this solved your issue, could you mark my answer as accepted? Thanks!
MoritzLost
CC BY-SA 4.0
2021-08-10T07:31:36.990Z
2021-08-10T07:31:36.990Z
MoritzLost
<p>I'm using this code to remove duplicate entries from my loop:</p>
<pre><code>{% set existingIds = [] %}
 {% for entry in entries %}
    {% if entry.id not in existingIds %}
  &lt;div class=&quot;column is-4&quot;&gt;
{% include '_blocks/small/entries.twig'  %}
&lt;/div&gt;
 {% set existingIds = existingIds|merge([entry.id]) %}
    {% endif %}
{% endfor %}
</code></pre>
<p>Everything working good but the problem is that if I have set to display 3 entries - I will get 2 or less if existingIds will be found. What I want to do is to replace that duplicate with the other entry to have always 3 entries to display.</p>

CC BY-SA 4.0
2021-08-10T05:59:32.220Z
Where do the `entries` come from? Are there more available entries to display in there? Can you simply query more items? How do you end up with duplicates in the first place?
MoritzLost
CC BY-SA 4.0
2021-08-10T06:39:03.910Z
It looks like this: https://pastecode.io/s/w5q2uqde So in this case I have one article duplicated and that leads that the last block (with 3 articles) display only 2 of them since one was displayed above.
Lukas Snarskis
CC BY-SA 4.0
2021-08-10T06:58:00.167Z
Why use three separate queries instead of just using one query to get the required number of entries?
MoritzLost
CC BY-SA 4.0
2021-08-10T07:05:01.370Z
I don't know how to display three different styling in one query
Lukas Snarskis
<forloop><loop>
Loop when removing existing ID's
# Loop when removing existing ID's

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

I'm using this code to remove duplicate entries from my loop:
{% set existingIds = [] %}
 {% for entry in entries %}
    {% if entry.id not in existingIds %}
  
{% include '_blocks/small/entries.twig'  %}

 {% set existingIds = existingIds|merge([entry.id]) %}
    {% endif %}
{% endfor %}

Everything working good but the problem is that if I have set to display 3 entries - I will get 2 or less if existingIds will be found. What I want to do is to replace that duplicate with the other entry to have always 3 entries to display.

**Tags:** forloop, loop
> **Comments:**
> **username_1**: Where do the `entries` come from? Are there more available entries to display in there? Can you simply query more items? How do you end up with duplicates in the first place?  
> **username_0**: It looks like this: https://pastecode.io/s/w5q2uqde So in this case I have one article duplicated and that leads that the last block (with 3 articles) display only 2 of them since one was displayed above.  
> **username_1**: Why use three separate queries instead of just using one query to get the required number of entries?  
> **username_0**: I don't know how to display three different styling in one query  

---

## 1 answers

### Answer by username_1 on 2021-08-10. Score: 1 | Accepted answer

Based on the example you linked: You can prevent duplicate entries by explicitly excluding the entries you've already seen using the id method. Since you already have an array of IDs you have already displayed  (existingIds), you only need to prepend 'not' to negate the query and exclude those entries:
https://craftcms.com/docs/3.x/entries.html#id
{% set featuredArticle = craft.entries
    .section('articles')
    .id(['not']|merge(existingIds))
    .one() %}

This will ensure you always get an entry you haven't displayed before. This also allows you to get rid of the offset().

Sidenote: I'm using one() instead of all() to execute the query. This returns only a single entry instead of an array of entries, so you can remove the limit(1) call as well. It also allows you to get rid of the loop, since the result is a single entry instead of an array of entries.

> **Comments:**
> **username_0**: Amazing! I find out how to use slice as well so now featured section looks like this: https://pastecode.io/s/tbmh68a0. I added id method to lower column since I don't want any of featured content to be display in it and it looks like this: https://pastecode.io/s/psqtax01 Is it correct way to implement everything?  
> **username_1**: @LukasSnarskis Looks good to me! If this solved your issue, could you mark my answer as accepted? Thanks!  

---

