<p>Out-of-the box, Craft doesn't offer such filters, but adding them isn't that hard <a href="https://craftcms.com/knowledge-base/custom-module-events" rel="nofollow noreferrer">using a module</a>.</p>
<p>You need to listen to 2 events:</p>
<ul>
<li><a href="https://docs.craftcms.com/api/v3/craft-base-element.html#events" rel="nofollow noreferrer"><code>\craft\elements\Entry::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES</code></a>: to add searchable attributes (the prefix you use in the search field, before the colon)</li>
<li><a href="https://docs.craftcms.com/api/v3/craft-base-element.html#events" rel="nofollow noreferrer"><code>\craft\elements\Entry::EVENT_DEFINE_KEYWORDS</code></a>: to set the value your custom searchable field</li>
</ul>
<p>Something like this should work (although I haven't tested):</p>
<pre><code>Event::on(
    \craft\elements\Entry::class,
    \craft\base\Element::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES,
    function(\craft\events\RegisterElementSearchableAttributesEvent $event) {
        $event-&gt;attributes[] = 'entryType';
        $event-&gt;attributes[] = 'typeId';
    }
);

Event::on(
    \craft\elements\Entry::class,
    \craft\base\Element::EVENT_DEFINE_KEYWORDS,
    function (\craft\events\DefineAttributeKeywordsEvent $event) {
        /** @var \craft\elements\Entry $entry */
        $entry = $event-&gt;sender;

        if ($event-&gt;attribute === 'entryType') {
            $event-&gt;keywords = $entry-&gt;type-&gt;handle;
        } elseif ($event-&gt;attribute === 'typeId') {
            $event-&gt;keywords = $entry-&gt;type-&gt;id;
        }
    }
);
</code></pre>

CC BY-SA 4.0
2021-12-23T14:13:12.387Z
Many thanks. I'll look into that.
Jonathan Schofield
CC BY-SA 4.0
2021-12-20T18:51:34.257Z
2021-12-20T18:51:34.257Z
nstCactus
<p>I’m aware of <a href="https://craftcms.stackexchange.com/questions/2118/filtering-searching-for-entries-by-category-in-the-control-panel">Filtering/searching for entries by category in the control panel</a>, but that doesn’t work for:</p>
<pre><code>entryType:&quot;String&quot;
</code></pre>
<p>…where ‘String’ is the entry type <code>name</code> or <code>handle</code>, or…</p>
<pre><code>typeId:Int
</code></pre>
<p>…where <code>Int</code> is the <code>entries</code> table’s <code>typeId</code> number.</p>
<p>Is something like this possible with some other syntax?</p>
<p>I can add <code>Entry Type</code> to the list scope and sort by it, but that’s not what I’m hoping for.</p>

<entries><control-panel><filtering>
Filtering lists of entries in the control panel by entry type
# Filtering lists of entries in the control panel by entry type

(Asked by: username_0 on 2021-12-20)

I’m aware of Filtering/searching for entries by category in the control panel, but that doesn’t work for:
entryType:"String"

…where ‘String’ is the entry type name or handle, or…
typeId:Int

…where Int is the entries table’s typeId number.
Is something like this possible with some other syntax?
I can add Entry Type to the list scope and sort by it, but that’s not what I’m hoping for.

**Tags:** entries, control-panel, filtering

---

## 1 answers

### Answer by username_1 on 2021-12-20. Score: 2

Out-of-the box, Craft doesn't offer such filters, but adding them isn't that hard using a module.
You need to listen to 2 events:

\craft\elements\Entry::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES: to add searchable attributes (the prefix you use in the search field, before the colon)
\craft\elements\Entry::EVENT_DEFINE_KEYWORDS: to set the value your custom searchable field

Something like this should work (although I haven't tested):
Event::on(
    \craft\elements\Entry::class,
    \craft\base\Element::EVENT_REGISTER_SEARCHABLE_ATTRIBUTES,
    function(\craft\events\RegisterElementSearchableAttributesEvent $event) {
        $event->attributes[] = 'entryType';
        $event->attributes[] = 'typeId';
    }
);

Event::on(
    \craft\elements\Entry::class,
    \craft\base\Element::EVENT_DEFINE_KEYWORDS,
    function (\craft\events\DefineAttributeKeywordsEvent $event) {
        /** @var \craft\elements\Entry $entry */
        $entry = $event->sender;

        if ($event->attribute === 'entryType') {
            $event->keywords = $entry->type->handle;
        } elseif ($event->attribute === 'typeId') {
            $event->keywords = $entry->type->id;
        }
    }
);

> **Comments:**
> **username_0**: Many thanks. I'll look into that.  

---

