Body: <p>I have two channels, <code>pages</code> and <code>products</code> and category groups for <code>categories</code> and <code>regions</code>.</p>
  <p>The <code>pages</code> entry type has a field where you can select entries from <code>products</code> based on their <code>category</code> and <code>region</code>.</p>
  <p>The <code>products</code> entry type has fields for <code>category</code>, <code>region</code>, and <code>postcode</code>.</p>
  <p>The <code>regions</code> category has a table field with a column for the region <code>name</code> and its <code>postcode</code>.</p>
  <p>So at the moment I have code that displays product entries based on what's selected in the <code>categories</code> and <code>regions</code> fields.</p>
  <pre><code>{% set relations = [
      'and',
      categories ? { targetElement: categories }, {# a list of category IDs #}
      regions ? { targetElement: regions } {# a list of region IDs #}
  ] | filter(o =&gt; o) %}
  
  {# Include #}
  {% set entries = craft.entries()
      .section('products')
      .orderBy('RAND()')
      .relatedTo(relations)
      .all() 
  %}
  </code></pre>
  <p>Now I also need to include <code>product</code> entries whose <code>postcode</code> matches that of the <code>region</code> that's been selected.</p>
  <p>I know it's probably going to include something like <code>targetElement: regions, field: 'postcodes.postcode'</code> and <code>sourceElement</code> but I can't quite get my head around it.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-06-21T07:53:54.723Z
Comments.Text: 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?
Comments.UserDisplayName: MoritzLost
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-06-21T23:18:28.247Z
Comments.Text: @MoritzLost yeah there can be multiple postcodes in a single region. Australia's a big place ;)
Comments.UserDisplayName: Tyssen
Tags: <categories><relations><relatedto>
Title: Matching entries against category custom field
ThreadText: # Matching entries against category custom field
  
  (Asked by: username_0 on 2023-06-21)
  
  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 = [
      'and',
      categories ? { targetElement: categories }, {# a list of category IDs #}
      regions ? { targetElement: regions } {# a list of region IDs #}
  ] | filter(o => o) %}
  
  {# Include #}
  {% set entries = craft.entries()
      .section('products')
      .orderBy('RAND()')
      .relatedTo(relations)
      .all() 
  %}
  
  ```
  
  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.
  
  **Tags:** categories, relations, relatedto
  
  > **Comments:**
  > **username_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?  
  > **username_0**: @username_1 yeah there can be multiple postcodes in a single region. Australia's a big place ;)  
  
  ---
  
  ## 0 answers
  
  