1

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?

2

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() %}
1
  • 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 Jan 20 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.