$49

Smart Map

Documentation  •  Changelog

Documentation

Filtering entries by subfield value

You can pass a "filter" parameter to only show matching entries...

{% set params = {
    filter: {
        country: 'United States'
    }
} %}

{% set entries = craft.entries.myFieldHandle(params).all() %}

The filter can be used for multiple subfields simultaneously...

{% set params = {
    filter: {
        city: 'Springfield',
        state: 'OH'
    }
} %}

If you want to include multiple values, simply pass the values in as an array...

{% set params = {
    filter: {
        country: ['United Kingdom', 'Germany', 'France']
    }
} %}

PHP

This can also be done in PHP...

use craft\elements\Entry;

$entries = Entry::find()
    ->section('mySection')
    ->myFieldHandle([
        'filter' => [
            'country' => 'United States'
        ]
    ])
    ->section('news')
    ->all();