<p>I'm not sure about an array of the <em>possible</em> values. But you can get the <em>actual</em> values. You can do this with twig's <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow">merge filter</a>. First get all the entries:</p>

<pre><code>{% set allEntries = craft.entries.section('whatever') %}
</code></pre>

<p>Then loop over the entries and add them to an array:</p>

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

{% for oneEntry in allEntries %}
  {% if oneEntry.storeBanner not in allValues %}
    {% set allValues = allValues | merge([oneEntry.storeBanner]) %}
  {% endif %}
{% endfor %}
</code></pre>

<p>Now <code>allValues</code> will be an array of the values</p>

<p>Things to notice:</p>

<ul>
<li>You need to set <code>allValues</code> outside of the for-loop. Otherwise it will only exist in the scope of the for loop, and not afterwards - ouside it.</li>
<li>You need to pass an array as the parameter of <code>merge</code>. In this case an array with one value: <code>[oneEntry.storeBanner]</code></li>
</ul>

CC BY-SA 3.0
2015-06-30T17:49:07.820Z
2015-06-30T17:49:07.820Z
Marion Newlevant
<p>Looking to loop through and filter based on possible values in a text entry field...I have a text field called storeBanner that has 11 possible values (but could have more). Just need a way to go through every entry and create an array with all possible values.</p>

CC BY-SA 3.0
2015-06-30T16:57:29.047Z
Can you provide more information? What have you tried so far?
Lindsey D
CC BY-SA 3.0
2015-06-30T16:59:43.140Z
Haven't tried anything yet. Not sure how best to go about that
brunam
<entries>
Is there an easy way to loop through all existing values of an entry field and store them in an array?
# Is there an easy way to loop through all existing values of an entry field and store them in an array?

(Asked by: username_0 on 2015-06-30)

Looking to loop through and filter based on possible values in a text entry field...I have a text field called storeBanner that has 11 possible values (but could have more). Just need a way to go through every entry and create an array with all possible values.

**Tags:** entries

> **Comments:**
> **username_1**: Can you provide more information? What have you tried so far?  
> **username_0**: Haven't tried anything yet. Not sure how best to go about that  

---

## 1 answers

### Answer by username_2 on 2015-06-30. Score: 1

I'm not sure about an array of the possible values. But you can get the actual values. You can do this with twig's merge filter. First get all the entries:
{% set allEntries = craft.entries.section('whatever') %}

Then loop over the entries and add them to an array:
{% set allValues = [] %}

{% for oneEntry in allEntries %}
  {% if oneEntry.storeBanner not in allValues %}
    {% set allValues = allValues | merge([oneEntry.storeBanner]) %}
  {% endif %}
{% endfor %}

Now allValues will be an array of the values
Things to notice:

You need to set allValues outside of the for-loop. Otherwise it will only exist in the scope of the for loop, and not afterwards - ouside it.
You need to pass an array as the parameter of merge. In this case an array with one value: [oneEntry.storeBanner]


---

