2

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.

1 Answer 1

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:

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;
        }
    }
);
1
  • Many thanks. I'll look into that. Commented Dec 23, 2021 at 14:13

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.