Answers.Body: <p>Do another call to <code>craft.entries</code> when you loop through the "area" entries and include the <code>section</code> and <code>relatedTo</code> params:</p>
  
  <pre><code>{% for entry in searchEntries %}
      {% set videos = craft.entries.section('videoSectionHandle').relatedTo(entry) %}
      {% for video in videos %}
           {# Output video here #}
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>If you're trying to maintain a one-to-one relationship it might make sense to limit the relation query to one result, and to include the <code>first</code> param to return the first (and only) result and not an array – then you can omit the nested <code>for</code> loop:</p>
  
  <pre><code>{% for entry in searchEntries %}
      {% set video = craft.entries.section('videoSectionHandle').relatedTo(entry).limit(1).first() %}
      {{ video ? #--Output video here--# }}
  {% endfor %}
  </code></pre>
  
  <p><a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="nofollow">You can read more about the relatedTo param here</a>, it's pretty powerful.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-22T19:40:32.837Z
Answers.LastActivityDate: 2015-03-23T07:04:03.930Z
Answers.LastEditDate: 2015-03-23T07:04:03.930Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have a section of "video" entries which are related to another section via an "area" field in the "video" section. When you do a search  on the front end by area then the related video displays as expected. What I also have in the area section is a text field full of postcodes, what I would like to happen is when you then do a search by postcode then the video displays that is related to that area, is that possible?</p>
  
  <p>Here is my code that works for searches by area:</p>
  
  <pre><code>{% set query = craft.request.getParam('search') %}
  {% set searchEntries = craft.entries.search(query).order('score') %}
  
  {% for entry in searchEntries.video(':notempty:') %}
    {% set video = entry.video %}
    {{ video.embed({ width: 340, height: 191, showinfo: false }) }}
  {% endfor %}
  </code></pre>
  
Tags: <relations><search>
Title: Get search results by relationship
ThreadText: # Get search results by relationship
  
  (Asked by: username_0 on 2015-03-21)
  
  I have a section of "video" entries which are related to another section via an "area" field in the "video" section. When you do a search on the front end by area then the related video displays as expected. What I also have in the area section is a text field full of postcodes, what I would like to happen is when you then do a search by postcode then the video displays that is related to that area, is that possible?
  
  Here is my code that works for searches by area:
  
  ```
  {% set query = craft.request.getParam('search') %}
  {% set searchEntries = craft.entries.search(query).order('score') %}
  
  {% for entry in searchEntries.video(':notempty:') %}
    {% set video = entry.video %}
    {{ video.embed({ width: 340, height: 191, showinfo: false }) }}
  {% endfor %}
  
  ```
  
  **Tags:** relations, search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-22. Score: 4 | Accepted answer
  
  Do another call to `craft.entries` when you loop through the "area" entries and include the `section` and `relatedTo` params:
  
  ```
  {% for entry in searchEntries %}
      {% set videos = craft.entries.section('videoSectionHandle').relatedTo(entry) %}
      {% for video in videos %}
           {# Output video here #}
      {% endfor %}
  {% endfor %}
  
  ```
  
  If you're trying to maintain a one-to-one relationship it might make sense to limit the relation query to one result, and to include the `first` param to return the first (and only) result and not an array – then you can omit the nested `for` loop:
  
  ```
  {% for entry in searchEntries %}
      {% set video = craft.entries.section('videoSectionHandle').relatedTo(entry).limit(1).first() %}
      {{ video ? #--Output video here--# }}
  {% endfor %}
  
  ```
  
  [You can read more about the relatedTo param here](http://buildwithcraft.com/docs/relations#the-relatedTo-param), it's pretty powerful.
  
  
  ---
  
  