<p>Your code should work. Make sure that your Settings → Fields → <strong>Navigation</strong> has <em>Use this field’s values as search keywords</em> checked.</p>
<p>Once you're sure it is checked, run <code>./craft resave/entries --update-search-index</code> and it should start working.</p>
<p>Note that instead of searching, you could use:</p>
<pre><code>{% set nav = craft.entries()
    .section('pages')
    .navigation('mainNavigation')
    .all() %}
</code></pre>

CC BY-SA 4.0
2021-01-20T15:04:28.257Z
Thanks! That did it. I knew there was something I was missing. Is there any benefit to doing it the other way, vs. searching?
artmem
CC BY-SA 4.0
2021-01-20T06:00:53.763Z
2021-01-20T06:00:53.763Z
Oli
<p>I have a channel, 'pages'. Within that channel is a dropdown 'navigation'. The values in the dropdown are 'mainNavigation' and 'hidden'.</p>
<p>I'm trying to set an entry query that only pulls entries where the navigation value is 'mainNavigation'.</p>
<p>This is the code I'm using, and I'm getting no results:</p>
<pre><code>{% set nav = craft.entries.section('pages').search('navigation:&quot;mainNavigation&quot;').all() %}
{% for link in nav %}
    {{link.title}} 
{% endfor %}
</code></pre>
<p>I know this should work. I've done it before. I copied the working code from another site, and copied the field name and value directly from the CP. I've stripped everything else out of the template. But no matter what I do, I get no results.</p>
<p>Has this functionality changed recently?</p>

<entries><search>
Filter entry query by a custom field value
# Filter entry query by a custom field value

(Asked by: username_0 on 2021-01-19)

I have a channel, 'pages'. Within that channel is a dropdown 'navigation'. The values in the dropdown are 'mainNavigation' and 'hidden'.
I'm trying to set an entry query that only pulls entries where the navigation value is 'mainNavigation'.
This is the code I'm using, and I'm getting no results:
{% set nav = craft.entries.section('pages').search('navigation:"mainNavigation"').all() %}
{% for link in nav %}
    {{link.title}} 
{% endfor %}

I know this should work. I've done it before. I copied the working code from another site, and copied the field name and value directly from the CP. I've stripped everything else out of the template. But no matter what I do, I get no results.
Has this functionality changed recently?

**Tags:** entries, search

---

## 1 answers

### Answer by username_1 on 2021-01-20. Score: 3 | Accepted answer

Your code should work. Make sure that your Settings → Fields → Navigation has Use this field’s values as search keywords checked.
Once you're sure it is checked, run ./craft resave/entries --update-search-index and it should start working.
Note that instead of searching, you could use:
{% set nav = craft.entries()
    .section('pages')
    .navigation('mainNavigation')
    .all() %}

> **Comments:**
> **username_0**: Thanks! That did it. I knew there was something I was missing. Is there any benefit to doing it the other way, vs. searching?  

---

