<p>You are using a dropdown field, so you can't query for the counties in use directly from the database. (This would be possible if you had chosen to use categories or tags for them.)</p>

<p>But what you can do is to loop all your jobs entries to collect their respective counties.</p>

<pre><code>{% set entries = craft.entries.section('jobs').limit(null) %}

{% set counties = [] %}
{% for entry in entries %}
    {% set counties = counties|merge({
        (entry.county.value): entry.county.value
    }) %}
{% endfor %}

{% set counties = counties|sort %}
</code></pre>

<p>Saving the county name also to the key of each array element makes sure you won't end up getting duplicates. When done use the <code>sort</code> filter to sort the list alphabetically.</p>

<p>Update: there seems to be a problem with getting the dropdown value with <code>entry.county</code> (the shortcut to get the value / calls the field models <code>__toString</code> method) when setting an array key, changing it to <code>entry.county.value</code> works.</p>

CC BY-SA 3.0
2015-10-08T14:16:03.040Z
Thanks Carlcs, I'll try this later tonight. Much appreciated!
Pathfinder
CC BY-SA 3.0
2015-10-12T10:39:37.727Z
Hi Carlcs, this seem to be working (I changed county to the jobCounty field name), but how do I now loop through the counties to display them?

I tried this:

    {% for county in counties %}
     <p>{{county}}</p>
    {% endfor %}

Derping a lot lately. Many thanks.
Pathfinder
CC BY-SA 3.0
2015-10-12T11:37:09.647Z
A big thanks to Carl, who contacted me directly via slack to help me with this one. We went through the issue and figured out the issue. He updated the post to reflect the fix. Very grateful for his time and support. Thanks!
Pathfinder
CC BY-SA 3.0
2015-10-08T14:00:08.563Z
2015-10-12T11:34:55.423Z
2015-10-12T11:34:55.423Z
carlcs
<p>For the life of me I can't seem to find an answer for this question, so here goes!</p>

<p>I have a field called jobCounty in a section called jobs.</p>

<p>The jobCounty is selected in the CP from a drop down list I've created of english county names.</p>

<p>There are about 30 entries each with most with different county names, but some repeat the same county name.</p>

<p>I want to create a form select, with options that are populated by the jobCounty names that have been selected, but avoid repeats. Ideally in alphabetical order.</p>

<p>This question seems to feel like it might be answering the same question but for for a different purpose.</p>

<p><a href="https://craftcms.stackexchange.com/questions/4436/related-entries-from-a-dynamic-dropdown">Related entries from a dynamic dropdown</a></p>

<p>Any help much appreciated</p>

<ul>
<li>Stephen</li>
</ul>

<templating><entries-field><drop-down>
How can I merge entry values to create a select dropdown
# How can I merge entry values to create a select dropdown

(Asked by: username_0 on 2015-10-08)

For the life of me I can't seem to find an answer for this question, so here goes!

I have a field called jobCounty in a section called jobs.

The jobCounty is selected in the CP from a drop down list I've created of english county names.

There are about 30 entries each with most with different county names, but some repeat the same county name.

I want to create a form select, with options that are populated by the jobCounty names that have been selected, but avoid repeats. Ideally in alphabetical order.

This question seems to feel like it might be answering the same question but for for a different purpose.

[Related entries from a dynamic dropdown](https://craftcms.stackexchange.com/questions/4436/related-entries-from-a-dynamic-dropdown)

Any help much appreciated

* Stephen

**Tags:** templating, entries-field, drop-down

---

## 1 answers

### Answer by username_1 on 2015-10-08. Score: 3 | Accepted answer

You are using a dropdown field, so you can't query for the counties in use directly from the database. (This would be possible if you had chosen to use categories or tags for them.)
But what you can do is to loop all your jobs entries to collect their respective counties.
{% set entries = craft.entries.section('jobs').limit(null) %}

{% set counties = [] %}
{% for entry in entries %}
    {% set counties = counties|merge({
        (entry.county.value): entry.county.value
    }) %}
{% endfor %}

{% set counties = counties|sort %}

Saving the county name also to the key of each array element makes sure you won't end up getting duplicates. When done use the sort filter to sort the list alphabetically.
Update: there seems to be a problem with getting the dropdown value with entry.county (the shortcut to get the value / calls the field models __toString method) when setting an array key, changing it to entry.county.value works.

> **Comments:**
> **username_0**: Thanks Carlcs, I'll try this later tonight. Much appreciated!  
> **username_0**: Hi Carlcs, this seem to be working (I changed county to the jobCounty field name), but how do I now loop through the counties to display them?  I tried this:      {% for county in counties %}      <p>{{county}}</p>     {% endfor %}  Derping a lot lately. Many thanks.  
> **username_0**: A big thanks to Carl, who contacted me directly via slack to help me with this one. We went through the issue and figured out the issue. He updated the post to reflect the fix. Very grateful for his time and support. Thanks!  

---

