<p>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 <code>relatedTo</code> 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?).</p>
<p>Additionally, you'll need to use the <a href="https://craftcms.com/docs/3.x/entries.html#anystatus" rel="nofollow noreferrer">anyStatus</a> parameter to fetch expired entries.</p>
<p>So to pull this off, you'll need to conduct the search against the other section and then find related entries, i.e.:</p>
<pre><code>{% set sectionBEntryIds = craft.entries.section('SECTION-B').search(searchParam).anyStatus().orderBy('score').ids() %}

{% set sectionAEntries = craft.entries.section('SECTION-A').relatedTo(sectionBEntryIds).all() %}
</code></pre>

CC BY-SA 4.0
2020-10-29T14:49:38.237Z
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
CC BY-SA 4.0
2020-10-29T15:56:14.547Z
Pretty sure that anyStatus() takes into account expired entries? https://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?
James Smith
CC BY-SA 4.0
2020-10-29T16:14:50.080Z
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
CC BY-SA 4.0
2020-10-29T17:29:14.290Z
Ah right I see now. I'll edit my answer...
James Smith
CC BY-SA 4.0
2020-10-29T20:20:40.763Z
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
CC BY-SA 4.0
2020-10-29T14:46:08.973Z
2020-10-29T17:38:04.277Z
2020-10-29T17:38:04.277Z
James Smith
<p>I have a search form with 1 simple input (q)</p>
<p>I also have 2 sections: SECTION-A &amp; SECTION-B</p>
<p>The search is for entries within <strong>SECTION A</strong>.</p>
<p>The entry I'm searching for contains a custom <a href="https://craftcms.com/docs/3.x/entries-fields.html#settings" rel="nofollow noreferrer">entriesField</a> from SECTION B which can contain a <em>posible disabled</em> 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.</p>
<p>This is what i have so far: (works perfectly with an <strong>enabled</strong> related entry from SECTION B)</p>
<pre><code>{% set entries = craft.entries.section('SECTION-A').search(searchParam).orderBy('score').all() %}
</code></pre>
<p>what I am trying:</p>
<pre><code>{% set entries = craft.entries.section('SECTION-A').search(searchParam ~ ' status: any').orderBy('score').all() %}
</code></pre>
<p>But this is not working, can anybody help me out here? :)</p>
<p>Screenshot clarification:
<a href="https://i.sstatic.net/pL9w1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pL9w1.png" alt="Example" /></a></p>
<p>When searching <strong>october</strong> (expired entry from SECTION-B), it is NOT showing me results.</p>
<p>When searching <strong>november</strong> (entry from SECTION-B), I get the results I am expecting</p>
<hr />
<p><em>some technical information:</em></p>
<ul>
<li>PHP version  7.3.22</li>
<li>Database driver &amp; version    MariaDB 10.3</li>
<li>Craft edition &amp; version  Craft Pro 3.5.14</li>
</ul>

<craft3><templating><search><query><status>
Craft 3 - Twig search query for entry with custom EntriesField containing disabled entry
# Craft 3 - Twig search query for entry with custom EntriesField containing disabled entry

(Asked by: username_0 on 2020-10-29)

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:

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

**Tags:** craft3, templating, search, query, status

---

## 1 answers

### Answer by username_1 on 2020-10-29. Score: 2

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() %}

> **Comments:**
> **username_0**: 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  
> **username_1**: Pretty sure that anyStatus() takes into account expired entries? https://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?  
> **username_0**: 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  
> **username_1**: Ah right I see now. I'll edit my answer...  
> **username_0**: 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?  

---

