Answers.Body: <pre><code>{% set range = entry.model %}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('title:' ~ range).relatedTo(categories) %}
  </code></pre>
  
  <p>If you are only searching titles I would add that in the search params as it will help the effectiveness of the search. In addition when setting a variable you do not need to use the <code>{{}}</code> syntax as it will automatically use the string representation of the the field if it is a text field.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:07:13.910Z
Answers.Text: Excellent, thanks a lot! I'll look into search filters more so I fully understand it for next time. Thanks!
Answers.UserDisplayName: JonnyT
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:07:48.927Z
Answers.Text: This page shows the various filters and what fields can be targeted for each element type. https://craftcms.com/docs/searching
Answers.UserDisplayName: mcclaskiem
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:09:30.263Z
Answers.Text: Yeah read that page but where I was going wrong was adding 'title:range' within the search brackets as opposed to ('title:' ~ range).
Answers.UserDisplayName: JonnyT
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:12:56.640Z
Answers.Text: Just an additional observation, if all entries have a "car model" you could make that a `category` field allowing for a `relatedTo` query which is much quicker. As you get more entries search will definitely underperform compared to a `relatedTo` query.
Answers.UserDisplayName: mcclaskiem
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:22:21.450Z
Answers.Text: Considered that first but the feed gets updated daily and not really sure how to import entries along with categories just yet so it seemed the way to go. There are about 180 entries at any one time so hopefully that should be OK.
Answers.UserDisplayName: JonnyT
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:27:51.883Z
Answers.Text: Depending on how you are importing I could probably show you how to do it pretty easily. Are you in Craft Slack?
Answers.UserDisplayName: mcclaskiem
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:35:39.637Z
Answers.Text: It's from a daily CSV file sent each night. Yeah that'll be great, I'll open it now.
Answers.UserDisplayName: JonnyT
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-04T13:04:26.753Z
Answers.LastActivityDate: 2016-05-04T13:04:26.753Z
Answers.UserDisplayName: mcclaskiem
Body: <p>I've got an entry page and at the bottom I would like to show related products and then underneath that, related offers. </p>
  
  <p>As the main page entry isn't assigned to any categories I've tried to use a custom field and the search param to show 'related' entries and this works fine, BUT, when I try and make it dynamic, it doesn't pull through. I'm guessing this is some kind of parsing order and that the custom field isn't parsed before the loop is created.</p>
  
  <p>This works fine: </p>
  
  <pre><code>{# To exclude certain category #}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('A1').relatedTo(categories) %}
  </code></pre>
  
  <p>But this doesn't when I try and make it dynamic:</p>
  
  <pre><code>{% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('{{ entry.model }}').relatedTo(categories) %}
  </code></pre>
  
  <p>I've also tried setting the variable first but it doesn't work:</p>
  
  <pre><code>{% set range = "{{ entry.model }}" %}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search(range).relatedTo(categories) %}
  </code></pre>
  
  <p>Hopefully this makes sense. Still in the basics I suppose of Craft but worth the learning curve. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T12:42:56.310Z
Comments.Text: Is A1 a title field or what would be a specific field on the model?
Comments.UserDisplayName: mcclaskiem
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T12:52:13.780Z
Comments.Text: Sorry, 'A1' is the model of the Audi vehicle so in this case I want to search all other offers that have 'A1' in the title e.g. 'New Audi A1...' etc.
Comments.UserDisplayName: JonnyT
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T12:58:33.803Z
Comments.Text: try adding `.search('title:' ~ range)` where range is the variable you set however your `set` needs to be `= entry.model` not the echo syntax. This question is somewhat similar as well http://craftcms.stackexchange.com/questions/9301/how-to-query-using-variables
Comments.UserDisplayName: mcclaskiem
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-04T13:06:41.627Z
Comments.Text: I've been searching yesterday and today and trying loads of various ways but never saw the post above. :/
Comments.UserDisplayName: JonnyT
Tags: <entries><categories><relations><field><search>
Title: Using the Search Filter with Entry Fields
ThreadText: # Using the Search Filter with Entry Fields
  
  (Asked by: username_0 on 2016-05-04)
  
  I've got an entry page and at the bottom I would like to show related products and then underneath that, related offers.
  
  As the main page entry isn't assigned to any categories I've tried to use a custom field and the search param to show 'related' entries and this works fine, BUT, when I try and make it dynamic, it doesn't pull through. I'm guessing this is some kind of parsing order and that the custom field isn't parsed before the loop is created.
  
  This works fine:
  
  ```
  {# To exclude certain category #}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('A1').relatedTo(categories) %}
  
  ```
  
  But this doesn't when I try and make it dynamic:
  
  ```
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('{{ entry.model }}').relatedTo(categories) %}
  
  ```
  
  I've also tried setting the variable first but it doesn't work:
  
  ```
  {% set range = "{{ entry.model }}" %}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search(range).relatedTo(categories) %}
  
  ```
  
  Hopefully this makes sense. Still in the basics I suppose of Craft but worth the learning curve.
  
  **Tags:** entries, categories, relations, field, search
  
  > **Comments:**
  > **username_1**: Is A1 a title field or what would be a specific field on the model?  
  > **username_0**: Sorry, 'A1' is the model of the Audi vehicle so in this case I want to search all other offers that have 'A1' in the title e.g. 'New Audi A1...' etc.  
  > **username_1**: try adding `.search('title:' ~ range)` where range is the variable you set however your `set` needs to be `= entry.model` not the echo syntax. This question is somewhat similar as well http://craftcms.stackexchange.com/questions/9301/how-to-query-using-variables  
  > **username_0**: I've been searching yesterday and today and trying loads of various ways but never saw the post above. :/  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-04. Score: 3 | Accepted answer
  
  ```
  {% set range = entry.model %}
  {% set categories = craft.categories.slug('not preferential') %}
  {% set entries = craft.entries.section('offers').search('title:' ~ range).relatedTo(categories) %}
  
  ```
  
  If you are only searching titles I would add that in the search params as it will help the effectiveness of the search. In addition when setting a variable you do not need to use the `{{}}` syntax as it will automatically use the string representation of the the field if it is a text field.
  
  > **Comments:**
  > **username_0**: Excellent, thanks a lot! I'll look into search filters more so I fully understand it for next time. Thanks!  
  > **username_1**: This page shows the various filters and what fields can be targeted for each element type. https://craftcms.com/docs/searching  
  > **username_0**: Yeah read that page but where I was going wrong was adding 'title:range' within the search brackets as opposed to ('title:' ~ range).  
  > **username_1**: Just an additional observation, if all entries have a "car model" you could make that a `category` field allowing for a `relatedTo` query which is much quicker. As you get more entries search will definitely underperform compared to a `relatedTo` query.  
  > **username_0**: Considered that first but the feed gets updated daily and not really sure how to import entries along with categories just yet so it seemed the way to go. There are about 180 entries at any one time so hopefully that should be OK.  
  > **username_1**: Depending on how you are importing I could probably show you how to do it pretty easily. Are you in Craft Slack?  
  > **username_0**: It's from a daily CSV file sent each night. Yeah that'll be great, I'll open it now.  
  
  ---
  
  