<p>Currently you are trying to compare objects with each other and of course they are always different since they have a different reference. <code>entry.vendor</code> is not a single selected value but the <code>field</code> with all it's options and possible values.</p>

<p>Please try </p>

<pre><code>{% for entry in craft.entries.section('orderBook').order('vendor').all() %}
    {% if entry.vendor.value not in vendorArray %}
        {% set vendorArray = vendorArray|merge([entry.vendor.value]) %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2018-04-10T12:16:24.143Z
2018-04-10T12:16:24.143Z
Robin Schambach
<p>I'm trying to use this slightly differently:
<a href="https://craftcms.stackexchange.com/questions/19730/how-do-i-omit-similar-content-in-a-for-loop-based-on-the-first-letter-in-title">How do I omit similar content in a for loop based on the first letter in title?</a></p>

<p>I have a for loop with several entries. One field is a drop-down with a bunch of vendors listed, and the user can select only one. I want a list of vendors that have been selected in the entries so that somebody can click on the vendor and see only the entries associated with that vendors. Clear as mud?</p>

<p>If no vendor is in any entries, then it should not be on the list.</p>

<pre><code>{% set vendorArray = [] %}

{% for entry in craft.entries.section('orderBook').order('vendor').all() %}
  {% if entry.vendor not in vendorArray %}
    {% set vendorArray = vendorArray|merge([entry.vendor]) %}
  {% endif %}
{% endfor %}

{% for link in vendorArray %}
  &lt;a href="{{ siteUrl }}{{ link }}"&gt;{{ link }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>The above link shows this working with only using the first letter of a field. I  want to use the entire field. I removed the filter |first and then I start to get duplicate vendors. I think the solution has something to do with the operator "not in", but I'm a noob so not too sure.</p>

<forloop><link>
Omitting repeated content in a for loop
# Omitting repeated content in a for loop

(Asked by: username_0 on 2018-04-10)

I'm trying to use this slightly differently:
How do I omit similar content in a for loop based on the first letter in title?
I have a for loop with several entries. One field is a drop-down with a bunch of vendors listed, and the user can select only one. I want a list of vendors that have been selected in the entries so that somebody can click on the vendor and see only the entries associated with that vendors. Clear as mud?
If no vendor is in any entries, then it should not be on the list.
{% set vendorArray = [] %}

{% for entry in craft.entries.section('orderBook').order('vendor').all() %}
  {% if entry.vendor not in vendorArray %}
    {% set vendorArray = vendorArray|merge([entry.vendor]) %}
  {% endif %}
{% endfor %}

{% for link in vendorArray %}
  {{ link }}
{% endfor %}

The above link shows this working with only using the first letter of a field. I  want to use the entire field. I removed the filter |first and then I start to get duplicate vendors. I think the solution has something to do with the operator "not in", but I'm a noob so not too sure.

**Tags:** forloop, link


---

## 1 answers

### Answer by username_1 on 2018-04-10. Score: 2 | Accepted answer

Currently you are trying to compare objects with each other and of course they are always different since they have a different reference. entry.vendor is not a single selected value but the field with all it's options and possible values.
Please try 
{% for entry in craft.entries.section('orderBook').order('vendor').all() %}
    {% if entry.vendor.value not in vendorArray %}
        {% set vendorArray = vendorArray|merge([entry.vendor.value]) %}
    {% endif %}
{% endfor %}


---

