Answers.Body: <p>You would need to setup two criteria models, one for each Smart Map field, and query for the element IDs. Merge these IDs and have a 3rd criteria model where you pass in the IDs to the <code>id</code> parameter.</p>
  
  <p>See this question for example code:  </p>
  
  <blockquote>
    <p><a href="https://craftcms.stackexchange.com/questions/1948/complex-logic-on-a-elementcriteriamodel-parameter">Complex logic on a ElementCriteriaModel parameter?</a></p>
  </blockquote>
  
  <p>Here's a blog post describing the technique in details:</p>
  
  <blockquote>
    <p><a href="https://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/" rel="nofollow noreferrer">Manipulating Craft's ElementCriteriaModel objects with Twig</a></p>
  </blockquote>
  
  <p>If you need better performance, have a look at the custom Yii query builder code I posted here:  </p>
  
  <blockquote>
    <p><a href="https://craftcms.stackexchange.com/questions/14618/how-can-i-query-for-entries-that-have-one-of-two-lightswitch-fields-enabled">How can I query for entries that have one of two Lightswitch fields enabled?</a></p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-23T05:48:03.337Z
Answers.Text: Beat me to it... and with a perfect answer! :)
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T15:31:20.280Z
Answers.Text: Thanks for the nudge into the right direction! Especially the blog post helps a lot.
Answers.UserDisplayName: medoingthings
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T15:43:46.953Z
Answers.Text: Do you have any clue how this would work using the [element api plugin](https://github.com/pixelandtonic/ElementAPI)?
Answers.UserDisplayName: medoingthings
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T16:13:03.190Z
Answers.Text: You can setup the criteria models in the transformer, have a look at this answer to get an idea of this http://craftcms.stackexchange.com/a/14691/125
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-22T22:24:26.993Z
Answers.LastActivityDate: 2016-05-23T06:00:40.173Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: carlcs
Body: <p>I have profiles (Users) that can have multiple addresses (currently two Smart Map fields called <code>profileAddress1</code> and <code>profileAddress2</code>).</p>
  
  <p>I know how to filter by a single address:</p>
  
  <pre><code>{% set results = craft.users({
      group: 'profiles',
      profileAddress1: {
          target: 'Cologne',
          range: 20
      }
  }) %}
  </code></pre>
  
  <p>How would I search across both fields? So if a profile had two addresses – one in Cologne and one in Munich – it should show up in the results in both search cases (Cologne and Munich).</p>
  
  <p>Is that even possible?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-23T06:04:03.940Z
Comments.Text: [Carl's answer](http://craftcms.stackexchange.com/a/15159/45) is spot on. You can only do a proximity search for one address field at a time. However, the workaround is to **perform two separate queries, and merge together the resulting entry ids.** Carl's answer (and linked references) describes the technique very well.
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-24T15:28:41.093Z
Comments.Text: @LindseyD thanks for the hint. Unfortunately I have trouble making clean searches for the separate address fields. Querying only for the `profileAddress2` field returns results whose `profileAddress2` field is empty. It seems like it’s querying for `profileAddress1` instead. Other results that should show up (because they have a matching address set in `profileAddress2` won’t show up. Is that maybe a bug in the SQL query or something? It’s driving me crazy :)
Comments.UserDisplayName: medoingthings
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-05-24T16:49:21.200Z
Comments.Text: Hmm, it might be a bug... email support@doublesecretagency.com, and we can sort it out there.
Comments.UserDisplayName: Lindsey D
Tags: <plugin-smartmap>
Title: How do I filter by multiple Smart Map addresses?
ThreadText: # How do I filter by multiple Smart Map addresses?
  
  (Asked by: username_0 on 2016-05-20)
  
  I have profiles (Users) that can have multiple addresses (currently two Smart Map fields called `profileAddress1` and `profileAddress2`).
  
  I know how to filter by a single address:
  
  ```
  {% set results = craft.users({
      group: 'profiles',
      profileAddress1: {
          target: 'Cologne',
          range: 20
      }
  }) %}
  
  ```
  
  How would I search across both fields? So if a profile had two addresses – one in Cologne and one in Munich – it should show up in the results in both search cases (Cologne and Munich).
  
  Is that even possible?
  
  **Tags:** plugin-smartmap
  
  > **Comments:**
  > **username_1**: [Carl's answer](http://craftcms.stackexchange.com/a/15159/45) is spot on. You can only do a proximity search for one address field at a time. However, the workaround is to **perform two separate queries, and merge together the resulting entry ids.** Carl's answer (and linked references) describes the technique very well.  
  > **username_0**: @username_1 thanks for the hint. Unfortunately I have trouble making clean searches for the separate address fields. Querying only for the `profileAddress2` field returns results whose `profileAddress2` field is empty. It seems like it’s querying for `profileAddress1` instead. Other results that should show up (because they have a matching address set in `profileAddress2` won’t show up. Is that maybe a bug in the SQL query or something? It’s driving me crazy :)  
  > **username_1**: Hmm, it might be a bug... email support@doublesecretagency.com, and we can sort it out there.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-05-22. Score: 4 | Accepted answer
  
  You would need to setup two criteria models, one for each Smart Map field, and query for the element IDs. Merge these IDs and have a 3rd criteria model where you pass in the IDs to the `id` parameter.
  
  See this question for example code:
  
  > [Complex logic on a ElementCriteriaModel parameter?](https://craftcms.stackexchange.com/questions/1948/complex-logic-on-a-elementcriteriamodel-parameter)
  
  Here's a blog post describing the technique in details:
  
  > [Manipulating Craft's ElementCriteriaModel objects with Twig](https://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/)
  
  If you need better performance, have a look at the custom Yii query builder code I posted here:
  
  > [How can I query for entries that have one of two Lightswitch fields enabled?](https://craftcms.stackexchange.com/questions/14618/how-can-i-query-for-entries-that-have-one-of-two-lightswitch-fields-enabled)
  
  > **Comments:**
  > **username_1**: Beat me to it... and with a perfect answer! :)  
  > **username_0**: Thanks for the nudge into the right direction! Especially the blog post helps a lot.  
  > **username_0**: Do you have any clue how this would work using the [element api plugin](https://github.com/pixelandtonic/ElementAPI)?  
  > **username_2**: You can setup the criteria models in the transformer, have a look at this answer to get an idea of this http://craftcms.stackexchange.com/a/14691/125  
  
  ---
  
  