2

I have entries using the SmartMap address field. I need to get just the entries that have a combination of city and state (city = "Beverly Hills" AND state = "CA"). I am currently only trying to get simpler search state working and only then will I move to state/city. I can get a "fuzzy" that to my understanding will get everything that has "CA" in any of the fields using:

{% set meetings = craft.entries.section('meetings').search('address:' ~ 'CA') %}

But I want to understand how to create a more specific search that specifically finds 'CA' in address.state.

When I try:

{% set meetings = craft.entries.section('meetings').search('address.state:' ~ 'CA') %}

the search returns nothing. No errors either.

Questions: How do I search specifically in a field like address.state?

Extending this question, how do I search address.state AND address.city?

2

It's more "filtering" than "searching", but take a look at this...

Filtering entries by subfield value

Set a filter parameter when creating your element criteria model...

{% set params = {
    filter: {
        city: 'Beverly Hills',
        state: 'CA'
    }
} %}

{% set meetings = craft.entries.address(params) %}
| improve this answer | |
  • Perfect! Thanks. Follow up...If I wanted to filter just by cities and group them so my 10 meetings in Beverly Hills just appears as on listing for Beverly Hills how would I do that with the "set params = " syntax? – Eric Snyder Mar 18 '18 at 19:52
  • I'm not sure I follow. You may want to ask a new question and go into a bit more detail. – Lindsey D Mar 19 '18 at 19:12
  • New question posted here. Hopefully clearer. :) craftcms.stackexchange.com/questions/25270/… – Eric Snyder Mar 19 '18 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.