<p>It's hard to say how you could include it since we don't know the rest of your search. Generally the best idea to search is with php and not with twig but you could grab all categories with the title (or whatever field it should be) with</p>

<pre><code>{% set categoryIds = craft.categories.title("Your search term").ids() %}
</code></pre>

<p>Then you can fetch all entries that are related to these categories with</p>

<pre><code>{% set entries = craft.entries.relatedTo(categoryIds).find() %}
</code></pre>

<p>However: if you just follow this <a href="https://craftcms.com/docs/searching#templating" rel="nofollow noreferrer">example</a> category titles are included in your search. </p>

CC BY-SA 3.0
2018-02-20T00:52:40.650Z
oh no, I left off my actual code, sorry. have edited to add. it's specifying particular fields, instead of the simpler example you shared, which I guess excludes the category titles, and since they're off in a whole other table in the database I don't know how to pull them in. But will look at your first thought on this as well. thank you!
Sapphireblue
CC BY-SA 3.0
2018-02-19T21:28:59.743Z
2018-02-19T21:28:59.743Z
Robin Schambach
<p>I have a request to extend an existing "advanced search" form (multiple fields, including keyword and a categories dropdown) so that entries with a category that matches the keyword input are returned.</p>

<p>For example, let's say my entries are all book authors, and among various entry fields like their bio and their published books, there's also a Topic category, and authors may be associated with 0-n categories.</p>

<p>And let's say I have an author Jane Smith, and one of her selected Topic categories is Poetry, but for some reason the word "poetry" does not exist in her bio or any of her book titles or for that matter anywhere at all in her main entry, but rather only as that category selection. </p>

<p>How would I modify my search so that anyone typing "poetry" into the keyword search field (rather than picking it from the Topics dropdown menu field) will get back Jane Smith as one of their results?</p>

<p>Still pretty new to Craft, but I feel like there has to be some way. If not via clever query construction on the results template, then maybe by some kind of way to automatically replicate the text of the author's topic categories into an entry field that's never displayed to users, just only exists to get that text into a place where it's picked up by the search index? Would be grateful for any thoughts. Thanks.</p>

<p>Existing search (this is followed by a bunch more Twig that merges these results with results of other entry types but I don't know that any of that is relevant here):</p>

<pre><code>{% set profileParams = {
    section: 'profiles',
    search: {
        query: 'title:' ~ query ~ ' OR ' ~ 
                     'position:' ~ query ~ ' OR ' ~ 
                     'jobTitle:' ~ query ~ ' OR ' ~ 
                     'institution:' ~ query,
        subLeft: true,
        subRight: true
    },
    order: 'score',
    limit: null
} %}

[...]

{% set profileEntries = craft.entries( profileParams ) %}
</code></pre>

<categories><search>
How to include search results where keyword input exists only as a category title?
# How to include search results where keyword input exists only as a category title?

(Asked by: username_0 on 2018-02-19)

I have a request to extend an existing "advanced search" form (multiple fields, including keyword and a categories dropdown) so that entries with a category that matches the keyword input are returned.
For example, let's say my entries are all book authors, and among various entry fields like their bio and their published books, there's also a Topic category, and authors may be associated with 0-n categories.
And let's say I have an author Jane Smith, and one of her selected Topic categories is Poetry, but for some reason the word "poetry" does not exist in her bio or any of her book titles or for that matter anywhere at all in her main entry, but rather only as that category selection. 
How would I modify my search so that anyone typing "poetry" into the keyword search field (rather than picking it from the Topics dropdown menu field) will get back Jane Smith as one of their results?
Still pretty new to Craft, but I feel like there has to be some way. If not via clever query construction on the results template, then maybe by some kind of way to automatically replicate the text of the author's topic categories into an entry field that's never displayed to users, just only exists to get that text into a place where it's picked up by the search index? Would be grateful for any thoughts. Thanks.
Existing search (this is followed by a bunch more Twig that merges these results with results of other entry types but I don't know that any of that is relevant here):
{% set profileParams = {
    section: 'profiles',
    search: {
        query: 'title:' ~ query ~ ' OR ' ~ 
                     'position:' ~ query ~ ' OR ' ~ 
                     'jobTitle:' ~ query ~ ' OR ' ~ 
                     'institution:' ~ query,
        subLeft: true,
        subRight: true
    },
    order: 'score',
    limit: null
} %}

[...]

{% set profileEntries = craft.entries( profileParams ) %}

**Tags:** categories, search

---

## 1 answers

### Answer by username_1 on 2018-02-19. Score: 1

It's hard to say how you could include it since we don't know the rest of your search. Generally the best idea to search is with php and not with twig but you could grab all categories with the title (or whatever field it should be) with
{% set categoryIds = craft.categories.title("Your search term").ids() %}

Then you can fetch all entries that are related to these categories with
{% set entries = craft.entries.relatedTo(categoryIds).find() %}

However: if you just follow this example category titles are included in your search.

> **Comments:**
> **username_0**: oh no, I left off my actual code, sorry. have edited to add. it's specifying particular fields, instead of the simpler example you shared, which I guess excludes the category titles, and since they're off in a whole other table in the database I don't know how to pull them in. But will look at your first thought on this as well. thank you!  

---

