I have two channels, pages and products and category groups for categories and regions.

The pages entry type has a field where you can select entries from products based on their category and region.

The products entry type has fields for category, region, and postcode.

The regions category has a table field with a column for the region name and its postcode.

So at the moment I have code that displays product entries based on what's selected in the categories and regions fields.

{% set relations = [
    categories ? { targetElement: categories }, {# a list of category IDs #}
    regions ? { targetElement: regions } {# a list of region IDs #}
] | filter(o => o) %}

{# Include #}
{% set entries = craft.entries()

Now I also need to include product entries whose postcode matches that of the region that's been selected.

I know it's probably going to include something like targetElement: regions, field: 'postcodes.postcode' and sourceElement but I can't quite get my head around it.

  • 1
    It's a normal table field? That's going to be difficult, table fields are difficult to filter by. Why is it a table field – are there multiple name + postcode rows in a single region category?
    – MoritzLost
    Commented Jun 21, 2023 at 7:53
  • 1
    @MoritzLost yeah there can be multiple postcodes in a single region. Australia's a big place ;)
    – Tyssen
    Commented Jun 21, 2023 at 23:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.