Answers.Body: <p>You have two different options. You can either use Crafts <a href="https://docs.craftcms.com/v2/searching.html" rel="nofollow noreferrer">search</a> so your string would be <code>listingAgent:*searchterm* OR coListingAgent:*searchterm*</code> or <code>listingAgent:searchterm OR coListingAgent:searchterm</code> if it should be an exact search</p>
  
  <pre><code>{% set results = craft.entries()
      .search({
          query: 'listingAgent:*' ~ getAgent ~ '* OR  coListingAgent:*' ~ getAgent  ~ '*',
          subLeft: true,
          subRight: true
      })
      .all() 
  %}
  </code></pre>
  
  <p>or you query correctly for the field values but I would prefer to do that in PHP instead of Twig</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T14:19:08.577Z
Answers.Text: Thanks for your help. Since this is just one parameter of a more complex search, how could I put that into syntax in my params variable (from my original post)?
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T14:21:32.353Z
Answers.Text: Why do you even want to do that. Twigs `|merge` function is so resource heavy I would suggest you not to use it too much. You can easily check if the parameter is set, if so attach it to the query
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T15:35:09.650Z
Answers.Text: I guess overall I just don't understand the method you're describing. Sorry I'm relatively new to this.
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T15:40:23.707Z
Answers.Text: `craft.entries` does not return an array of elements but an object of type `query` you can call all the functions you would like in the query in order to attach your criterias. You can do `{% set query = craft.entries.section('whatever') %}` and then append certain values `{% do query.search(getAgent) %}` and to fetch the entries `{% set entries = query.all() %}`
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T16:47:26.923Z
Answers.Text: Thank you. That makes sense. Could you help me with the query syntax? I have query: 'listingAgent:* ~ address ~ '* OR  coListingAgent:*' ~ address  ~ '*', and I'm getting an error Unexpected character " ' ".
Answers.UserDisplayName: triplethreat23
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-03T08:43:26.283Z
Answers.Text: @triplethreat23 I had a syntax error in my code (missing one `'`) and you copied it
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-02T14:06:02.067Z
Answers.LastActivityDate: 2018-05-03T08:43:04.833Z
Answers.LastEditDate: 2018-05-03T08:43:04.833Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm building a search form with filters. This is one of the filters.
  I would like to use the parameter "agent" and have it search a text field called "listingAgent" and "coListingAgent" to check for a match either place.  I tried the code below, but can't seem to get it to work.</p>
  
  <pre><code>    {% set getAgent = craft.request.getParam('agent') %}
      {% if getAgent %}
          {% set params = params|merge({ 'listingAgent':getAgent, 'coListingAgent':getAgent }) %}
      {% endif %}
  </code></pre>
  
  <p>additional info:
  I noticed that setting the params twice (like below) is looking for a match in both fields. I am looking for a match in either field. Does anyone know how to go about doing this?</p>
  
  <pre><code>{% set getAgent = craft.request.getParam('agent') %}
      {% if getAgent %}
          {% set params = params|merge({'listingAgent':getAgent}) %}
          {% set params = params|merge({'coListingAgent':getAgent}) %}
      {% endif %}
  
  {% set entries = craft.entries(params).search() %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-02T05:05:17.407Z
Comments.Text: Have you read the docs? https://docs.craftcms.com/v2/searching.html
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-02T13:50:21.127Z
Comments.Text: I did and I got the impression I could use "OR", I tried  {% set params = params|merge({'listingAgent':getAgent} OR {'coListingAgent':getAgent})and get the error back Arguments must be separated by a comma. Unexpected token "name" of value "OR" ("punctuation" expected with value ",").
Comments.UserDisplayName: triplethreat23
Tags: <search><merge>
Title: Search Multiple Fields Same Parameter
ThreadText: # Search Multiple Fields Same Parameter
  
  (Asked by: username_0 on 2018-05-01)
  
  I'm building a search form with filters. This is one of the filters.
  I would like to use the parameter "agent" and have it search a text field called "listingAgent" and "coListingAgent" to check for a match either place. I tried the code below, but can't seem to get it to work.
  
  ```
      {% set getAgent = craft.request.getParam('agent') %}
      {% if getAgent %}
          {% set params = params|merge({ 'listingAgent':getAgent, 'coListingAgent':getAgent }) %}
      {% endif %}
  
  ```
  
  additional info:
  I noticed that setting the params twice (like below) is looking for a match in both fields. I am looking for a match in either field. Does anyone know how to go about doing this?
  
  ```
  {% set getAgent = craft.request.getParam('agent') %}
      {% if getAgent %}
          {% set params = params|merge({'listingAgent':getAgent}) %}
          {% set params = params|merge({'coListingAgent':getAgent}) %}
      {% endif %}
  
  {% set entries = craft.entries(params).search() %}
  
  ```
  
  **Tags:** search, merge
  
  > **Comments:**
  > **username_1**: Have you read the docs? https://docs.craftcms.com/v2/searching.html  
  > **username_0**: I did and I got the impression I could use "OR", I tried  {% set params = params|merge({'listingAgent':getAgent} OR {'coListingAgent':getAgent})and get the error back Arguments must be separated by a comma. Unexpected token "name" of value "OR" ("punctuation" expected with value ",").  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-02. Score: 1
  
  You have two different options. You can either use Crafts [search](https://docs.craftcms.com/v2/searching.html) so your string would be `listingAgent:*searchterm* OR coListingAgent:*searchterm*` or `listingAgent:searchterm OR coListingAgent:searchterm` if it should be an exact search
  
  ```
  {% set results = craft.entries()
      .search({
          query: 'listingAgent:*' ~ getAgent ~ '* OR  coListingAgent:*' ~ getAgent  ~ '*',
          subLeft: true,
          subRight: true
      })
      .all() 
  %}
  
  ```
  
  or you query correctly for the field values but I would prefer to do that in PHP instead of Twig
  
  > **Comments:**
  > **username_0**: Thanks for your help. Since this is just one parameter of a more complex search, how could I put that into syntax in my params variable (from my original post)?  
  > **username_1**: Why do you even want to do that. Twigs `|merge` function is so resource heavy I would suggest you not to use it too much. You can easily check if the parameter is set, if so attach it to the query  
  > **username_0**: I guess overall I just don't understand the method you're describing. Sorry I'm relatively new to this.  
  > **username_1**: `craft.entries` does not return an array of elements but an object of type `query` you can call all the functions you would like in the query in order to attach your criterias. You can do `{% set query = craft.entries.section('whatever') %}` and then append certain values `{% do query.search(getAgent) %}` and to fetch the entries `{% set entries = query.all() %}`  
  > **username_0**: Thank you. That makes sense. Could you help me with the query syntax? I have query: 'listingAgent:* ~ address ~ '* OR  coListingAgent:*' ~ address  ~ '*', and I'm getting an error Unexpected character " ' ".  
  > **username_1**: @username_0 I had a syntax error in my code (missing one `'`) and you copied it  
  
  ---
  
  