1

James helped me with part one and it's working well: Filtering entries via a dropdown inside a Matrix Block

Now I would also like to filter by a table field as well. The table is extras and the columns I want to filter by is type - a dropdown field where one example value is workshop. Based on the previous answer and my head, this is what I'm thinking:

{% set blockIds = craft.matrixBlocks.type('event').extras('type.workshop').ids() %}
{% set eventsQuery = craft.entries.section('events').events(blockIds) %}

I'd appreciate any extra help! Thanks!

1 Answer 1

2

Searching table fields exactly is a bit difficult, because the selected values are stored as a JSON blob in the database. So you can't really query for specific values in specific columns directly. However, you can use the search index. The search index will include the entered values in all rows and columns. In the case of dropdown fields, the search index will include the handles of the selected values, not the option labels.

{% set eventsQuery = craft.entries()
    .section('events')
    .search('events:workshop')
%}

However, it's impossible to distinguish between columns, so if any of the other columns include the term workshop, those will be found by this query as well.

Searching tables is very imprecise, which is why I usually prefer to use categories and category fields for data like this. This makes it much easier to filter precisely by category using element relation filters.

1
  • 1
    Thanks for that! I actually tried search immediately after posting and to my surprise it worked. It doesn't need to be too precise in this case, so I'm happy to go with it. Thanks!
    – bigdev
    Mar 3, 2023 at 14:15

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.