Answers.Body: <p>Your syntax is a bit off – the <code>search()</code> parameter doesn't accept multiple parameters, only a <a href="https://craftcms.com/docs/searching#supported-syntaxes" rel="nofollow">search query</a> (e.g. <code>.search('body:foobar')</code>) or an object containing the search query plus <a href="https://craftcms.com/docs/config-settings#defaultSearchTermOptions" rel="nofollow">search term options</a>. In your case, you're actually passing an object (<code>.search(entry.clientsOrAgency)</code>), in which case Craft will look for a <code>query</code> parameter on that object (the second parameter is just ignored). Hence your error.</p>
  
  <p>That being said, here's what you probably want:</p>
  
  <pre><code>{% set testimonial = craft.entries.section('testimonials').search('clientsOrAgency:'~type).order('RAND()').limit(1) %}
  </code></pre>
  
  <p>The above will search for entries in the <code>testimonials</code> section, which has the value equal to <code>type</code> in each <code>clientsOrAgency</code> field.</p>
  
  <p>However – unless you need (which can be enabled <a href="https://craftcms.com/support/enabling-fuzzy-search-by-default" rel="nofollow">as a default</a> for all searching in Craft, or per-search using search term options mentioned above) for the <code>clientsOrAgency</code> field, I don't actually think using <code>search()</code> is the appropriate approach here. The following would be easier and probably more performant:</p>
  
  <pre><code>{% set testimonial = craft.entries.section('testimonials').clientsOrAgency(type).order('RAND()').limit(1) %}
  </code></pre>
  
  <p>Also, you should probably add <code>.first()</code> to your <code>craft.entries</code> query, in order to only pull a single entry:</p>
  
  <pre><code>{% set testimonial = craft.entries.section('testimonials').clientsOrAgency(type).order('RAND()').limit(1).first() %}
  
  {% if testimonial %}
      ...
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T15:44:30.870Z
Answers.Text: That's perfect. Used the second code block - wasn't aware that you could search a field in that way.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T16:02:34.003Z
Answers.Text: Awesome. Yeah, you can even do more advanced stuff like for example `.clientsOrAgency(type~'*')`, to search for `clientsOrAgency` values _starting with_ `type`.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-04T15:42:29.933Z
Answers.LastActivityDate: 2016-10-04T16:04:10.007Z
Answers.LastEditDate: 2016-10-04T16:04:10.007Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have a template where I would like to pass a search parameter to a craft.entries.section in an included template. The current main template has this:</p>
  
  <pre><code>{% include "_includes/testimonial" with
    { type: "agency" } 
    %}
  </code></pre>
  
  <p>Then in the include I have this code where <strong>entry.clientsOrAgency</strong> is a dropdown field and I want it to only show results of the "type" passed in the parent template.</p>
  
  <pre><code>{# get one random testimonial entry #}
  {% set testimonial = craft.entries.section('testimonials').search(entry.clientsOrAgency,type).order('RAND()').limit(1) %}
  
  {% for quotes in testimonial %}
  &lt;div class="testimonial"&gt;
  
    {# matrix field is 'testimonial' - find different quote types #}
    {% for quote in quotes.testimonial %}
      more code here
    {% endfor %} {# quotes.testimonial #}
  
  &lt;/div&gt;&lt;!--testimonial--&gt;
  {% endfor %}{# quote in testimonial #}
  </code></pre>
  
  <p>The above code results in a template error <strong>Undefined index: query</strong></p>
  
  <p>Not sure how to resolve this.</p>
  
Tags: <templating><include><params>
Title: search parameter passed to include
ThreadText: # search parameter passed to include
  
  (Asked by: username_0 on 2016-10-04)
  
  I have a template where I would like to pass a search parameter to a craft.entries.section in an included template. The current main template has this:
  
  ```
  {% include "_includes/testimonial" with
    { type: "agency" } 
    %}
  
  ```
  
  Then in the include I have this code where **entry.clientsOrAgency** is a dropdown field and I want it to only show results of the "type" passed in the parent template.
  
  ```
  {# get one random testimonial entry #}
  {% set testimonial = craft.entries.section('testimonials').search(entry.clientsOrAgency,type).order('RAND()').limit(1) %}
  
  {% for quotes in testimonial %}
  <div class="testimonial">
  
    {# matrix field is 'testimonial' - find different quote types #}
    {% for quote in quotes.testimonial %}
      more code here
    {% endfor %} {# quotes.testimonial #}
  
  </div><!--testimonial-->
  {% endfor %}{# quote in testimonial #}
  
  ```
  
  The above code results in a template error **Undefined index: query**
  
  Not sure how to resolve this.
  
  **Tags:** templating, include, params
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-04. Score: 3 | Accepted answer
  
  Your syntax is a bit off – the `search()` parameter doesn't accept multiple parameters, only a [search query](https://craftcms.com/docs/searching#supported-syntaxes) (e.g. `.search('body:foobar')`) or an object containing the search query plus [search term options](https://craftcms.com/docs/config-settings#defaultSearchTermOptions). In your case, you're actually passing an object (`.search(entry.clientsOrAgency)`), in which case Craft will look for a `query` parameter on that object (the second parameter is just ignored). Hence your error.
  
  That being said, here's what you probably want:
  
  ```
  {% set testimonial = craft.entries.section('testimonials').search('clientsOrAgency:'~type).order('RAND()').limit(1) %}
  
  ```
  
  The above will search for entries in the `testimonials` section, which has the value equal to `type` in each `clientsOrAgency` field.
  
  However – unless you need (which can be enabled [as a default](https://craftcms.com/support/enabling-fuzzy-search-by-default) for all searching in Craft, or per-search using search term options mentioned above) for the `clientsOrAgency` field, I don't actually think using `search()` is the appropriate approach here. The following would be easier and probably more performant:
  
  ```
  {% set testimonial = craft.entries.section('testimonials').clientsOrAgency(type).order('RAND()').limit(1) %}
  
  ```
  
  Also, you should probably add `.first()` to your `craft.entries` query, in order to only pull a single entry:
  
  ```
  {% set testimonial = craft.entries.section('testimonials').clientsOrAgency(type).order('RAND()').limit(1).first() %}
  
  {% if testimonial %}
      ...
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: That's perfect. Used the second code block - wasn't aware that you could search a field in that way.  
  > **username_1**: Awesome. Yeah, you can even do more advanced stuff like for example `.clientsOrAgency(type~'*')`, to search for `clientsOrAgency` values _starting with_ `type`.  
  
  ---
  
  