TransWikia.com

Smart Map - How to search by a field in address?

Craft CMS Asked on April 8, 2021

I have entries using the Smart Map 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?

One Answer

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) %}

Correct answer by Lindsey D on April 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP