I have a search form with 1 simple input (q)

I also have 2 sections: SECTION-A & SECTION-B

The search is for entries within SECTION A.

The entry I'm searching for contains a custom entriesField from SECTION B which can contain a posible disabled entry because they have an expiryDate. But they still need to be searchable when typing something the disabled entry contains. I can't figure out what to do with my query.

This is what i have so far: (works perfectly with an enabled related entry from SECTION B)

{% set entries = craft.entries.section('SECTION-A').search(searchParam).orderBy('score').all() %}

what I am trying:

{% set entries = craft.entries.section('SECTION-A').search(searchParam ~ ' status: any').orderBy('score').all() %}

But this is not working, can anybody help me out here? :)

Screenshot clarification: Example

When searching october (expired entry from SECTION-B), it is NOT showing me results.

When searching november (entry from SECTION-B), I get the results I am expecting

some technical information:

  • PHP version 7.3.22
  • Database driver & version MariaDB 10.3
  • Craft edition & version Craft Pro 3.5.14

1 Answer 1


The search parameter only searches the element that is the subject of your element query (i.e., the source entry) - it does not search related entries. For that you need to use the relatedTo parameter. (I'm not sure why you're getting a successful result for the November entry - perhaps the source entry also has the word November in it somewhere?).

Additionally, you'll need to use the anyStatus parameter to fetch expired entries.

So to pull this off, you'll need to conduct the search against the other section and then find related entries, i.e.:

{% set sectionBEntryIds = craft.entries.section('SECTION-B').search(searchParam).anyStatus().orderBy('score').ids() %}

{% set sectionAEntries = craft.entries.section('SECTION-A').relatedTo(sectionBEntryIds).all() %}
  • Not realy, it's not the entries in the section that are disabled (because than anyStatus would be applied) It's the entry within the customField (entries field) that contains a 'expired' entry. Added a screenshot for more clarification
    – Kevon
    Commented Oct 29, 2020 at 14:49
  • Pretty sure that anyStatus() takes into account expired entries? craftcms.com/docs/3.x/entries.html#status .. or are you saying that you have a custom field for the expiry date instead of the built-in one? Commented Oct 29, 2020 at 15:56
  • I've added more clarification in my question above. The Entry "test" has a custom "entriesField" where I added the entry "28-October-2020" (expired with build in expiryDate). Now, when I search for the word October, it is not giving me the "Test" entry. When searching for November, I do get back the other "Test" entry
    – Kevon
    Commented Oct 29, 2020 at 16:14
  • Ah right I see now. I'll edit my answer... Commented Oct 29, 2020 at 17:29
  • That doesn't work :( I updated my question again. FYI: the entry which contains november doesn't have any tekst containing the word november. I made a new test with an extra entry in which I related a date from december, and if I search for it it comes back in the results. So there has to be some way to give a parameter into the search to ignore status from related fields right?
    – Kevon
    Commented Oct 29, 2020 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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