<p>Author of Smart Map here... I can't tell exactly what question you are asking, so I'll give an answer based on my understanding of the problem.</p>
<p>It looks like your biggest problem is here:</p>
<pre><code>    {% set criteria = {
        section: 'jobListings',
        state: state,
        truckType: trucktype,
        city: city,
        jobAddress: {
            zip: target
        }
    } %}
</code></pre>
<p>If you are trying to filter by the <code>state</code>, <code>city</code>, and <code>zip</code> of the <strong>jobAddress</strong> field, then those will need to be contained in a <code>filter</code> parameter...</p>
<pre><code>    {% set criteria = {
        section: 'jobListings',
        truckType: trucktype,
        jobAddress: {
            filter: {
                state: state,
                city: city,
                zip: target
            }
        }
    } %}
</code></pre>
<p>Check out the docs on <a href="https://plugins.doublesecretagency.com/smart-map/filtering-entries-by-subfield-value/" rel="nofollow noreferrer">Filtering entries by subfield value</a> for more information. Hope that helps!</p>

CC BY-SA 4.0
2020-01-30T22:02:39.277Z
2021-01-01T07:28:24.633Z
2021-01-01T07:28:24.633Z
Lindsey D
<p>I am trying to complete an advanced search query with Smart Map, but I can't seem to quite get it. I tried to merge several URL parameters, and they seem to work fine except when it comes down to Smart Map's query.</p>
<p>I followed along with the example <a href="https://plugins.doublesecretagency.com/smart-map/sorting-entries-by-closest-locations/" rel="nofollow noreferrer">here</a>, but it's not fully rendering correctly. The Smart Map field is named <code>jobAddress</code>, in the section called <code>jobListings</code>.</p>
<p>Can anyone take a peek at my code and perhaps point out what I am doing wrong? Disclaimer... I am extremely new to Craft. I appreciate your help and guidance!</p>
<pre class="lang-html prettyprint-override"><code>{% extends &quot;_layout&quot; %}

{% block main %}

    {# Set variables for each possible param: #}
    {% set state = craft.app.request.getParam('state') %}
    {% set trucktype = craft.app.request.getParam('trucktype') %}
    {% set city = craft.app.request.getParam('city') %}
    {% set target = craft.app.request.getParam('zip') %}
    {% set range = craft.app.request.getParam('range') %}

    {# Here we set the criteria and combine all the parameter variables #}
    {% set criteria = {
        section: 'jobListings',
        state: state,
        truckType: trucktype,
        city: city,
        jobAddress:{
            zip:target
        }
    } %}

    {# Pass the criteria object to the query builder: #}
    {% set query = craft.entries(criteria) %}

    {% if target is not empty and range is not empty %}
        {% set query = query|merge({
            jobAddress:{
                range: range
            }
        }) %}
    {% endif %}

    {# We build the map location based on criteria #}
    &lt;div class=&quot;container-fluid&quot; id=&quot;map&quot;&gt;
        &lt;div class=&quot;row bg-secondary&quot;&gt;
            &lt;div class=&quot;col-sm-12 p-0&quot;&gt;
                {% set locations = query %}
                {% set options = {
                    height:400,
                    zoom: 5,
                    'markerInfo': 'searchjobs/infoBubble',
                    markerOptions: {
                        icon: 'https://maps.google.com/mapfiles/ms/icons/green-dot.png'
                    }
                } %}
                {{ craft.smartMap.map(locations, options) }}
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    {# DISPLAY Search Results #}
    &lt;div class=&quot;container-fluid pt-5 pb-1 jobs-index&quot;&gt;
        &lt;h1 class=&quot;text-center&quot;&gt;Search Results&lt;/h1&gt;
        {# Set up pagination, and let it grab the current page's results: #}
        {% paginate query as pageInfo, results %}

        {% for result in results %}
            &lt;div class=&quot;row p-4&quot;&gt;
                &lt;div class=&quot;col-sm-8 offset-sm-2 col-md-6 offset-md-3 bg-light p-2&quot;&gt;
                    &lt;h3 class=&quot;job-header&quot;&gt;{{ result.title }}&lt;/h3&gt;
                    &lt;p&gt;&lt;strong&gt;&lt;em&gt;Truck:&lt;/em&gt;&lt;/strong&gt; {{ result.truckType }}&lt;/p&gt;
                    &lt;p&gt;&lt;strong&gt;&lt;em&gt;State&lt;/em&gt;&lt;/strong&gt;{{ result.state}}&lt;/p&gt;
                    &lt;p&gt;&lt;strong&gt;&lt;em&gt;City:&lt;/em&gt;&lt;/strong&gt; {{ result.city}}&lt;/p&gt;
                    &lt;a class=&quot;btn btn-small btn-details&quot; href=&quot;/jobs/{{result.slug}}&quot;&gt;Get More Details &amp;nbsp; &lt;i class=&quot;fas fa-arrow-right&quot;&gt;&lt;/i&gt; &lt;/a&gt;
                    &lt;p class=&quot;pt-2&quot;&gt;&lt;strong&gt;Benefits: &lt;/strong&gt;
                        {% for option in result.jobBenefits %}
                            {{ option.value }}
                            {# Value: {{ option }} or {{ option.value }} #}
                        {% endfor %}
                    &lt;/p&gt;
                    {# Show the Radius #}
                    &lt;p&gt;&lt;strong&gt;{{ result.jobAddress.distance | number_format(1) }} miles away&lt;/strong&gt;&lt;/p&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        {% endfor %}

        &lt;div class=&quot;search-again&quot;&gt;
            &lt;h3 class=&quot;text-center&quot;&gt;Didn't find what you're looking for?&lt;/h3&gt;
            &lt;a class=&quot;btn btn-lg btn-success search-again-btn&quot; href=&quot;/jobs&quot;&gt;Search Again&lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;
{% endblock %}

</code></pre>
<p>Here is a live preview of the <a href="https://conversionia.frb.io/jobs" rel="nofollow noreferrer">current site...</a></p>

<query><plugin-smartmap>
Advanced Search Filter
# Advanced Search Filter

(Asked by: username_0 on 2020-01-23)

I am trying to complete an advanced search query with Smart Map, but I can't seem to quite get it. I tried to merge several URL parameters, and they seem to work fine except when it comes down to Smart Map's query.
I followed along with the example here, but it's not fully rendering correctly. The Smart Map field is named jobAddress, in the section called jobListings.
Can anyone take a peek at my code and perhaps point out what I am doing wrong? Disclaimer... I am extremely new to Craft. I appreciate your help and guidance!
{% extends "_layout" %}

{% block main %}

    {# Set variables for each possible param: #}
    {% set state = craft.app.request.getParam('state') %}
    {% set trucktype = craft.app.request.getParam('trucktype') %}
    {% set city = craft.app.request.getParam('city') %}
    {% set target = craft.app.request.getParam('zip') %}
    {% set range = craft.app.request.getParam('range') %}

    {# Here we set the criteria and combine all the parameter variables #}
    {% set criteria = {
        section: 'jobListings',
        state: state,
        truckType: trucktype,
        city: city,
        jobAddress:{
            zip:target
        }
    } %}

    {# Pass the criteria object to the query builder: #}
    {% set query = craft.entries(criteria) %}

    {% if target is not empty and range is not empty %}
        {% set query = query|merge({
            jobAddress:{
                range: range
            }
        }) %}
    {% endif %}

    {# We build the map location based on criteria #}
    
        
            
                {% set locations = query %}
                {% set options = {
                    height:400,
                    zoom: 5,
                    'markerInfo': 'searchjobs/infoBubble',
                    markerOptions: {
                        icon: 'https://maps.google.com/mapfiles/ms/icons/green-dot.png'
                    }
                } %}
                {{ craft.smartMap.map(locations, options) }}
            
        
    

    {# DISPLAY Search Results #}
    
        Search Results
        {# Set up pagination, and let it grab the current page's results: #}
        {% paginate query as pageInfo, results %}

        {% for result in results %}
            
                
                    {{ result.title }}
                    Truck: {{ result.truckType }}
                    State{{ result.state}}
                    City: {{ result.city}}
                    Get More Details    
                    Benefits: 
                        {% for option in result.jobBenefits %}
                            {{ option.value }}
                            {# Value: {{ option }} or {{ option.value }} #}
                        {% endfor %}
                    
                    {# Show the Radius #}
                    {{ result.jobAddress.distance | number_format(1) }} miles away
                
            
        {% endfor %}

        
            Didn't find what you're looking for?
            Search Again
        
    
{% endblock %}


Here is a live preview of the current site...

**Tags:** query, plugin-smartmap


---

## 1 answers

### Answer by username_1 on 2020-01-30. Score: 1

Author of Smart Map here... I can't tell exactly what question you are asking, so I'll give an answer based on my understanding of the problem.
It looks like your biggest problem is here:
    {% set criteria = {
        section: 'jobListings',
        state: state,
        truckType: trucktype,
        city: city,
        jobAddress: {
            zip: target
        }
    } %}

If you are trying to filter by the state, city, and zip of the jobAddress field, then those will need to be contained in a filter parameter...
    {% set criteria = {
        section: 'jobListings',
        truckType: trucktype,
        jobAddress: {
            filter: {
                state: state,
                city: city,
                zip: target
            }
        }
    } %}

Check out the docs on Filtering entries by subfield value for more information. Hope that helps!


---

