julienbechade/acf-location-field

meta query

Closed this issue · 5 comments

Hi there, I'm trying to do a meta_query to show only posts with the location field value of a specified city within a specified country. This is what I've got now:

$args = array(
'post_type' => 'venue',
'meta_query' => array(
array(
'key' => 'city',
'value' => array('bergen', 'norway'),
'compare' => 'IN',
)
)
);

Doesnt work at all. Probably cause the value of the field is an array. Any suggestions?

Sorry for the late answer…

The value is NOT an array, it becomes only an array when using ACF's API functions get_field();or the_field(); in your template.
The value is saved in your database as a simple string:

address|coordinates

So perhaps this could work:

$args = array(
    'post_type' => 'venue',
    'meta_query' => array(
        array(
            'key' => 'city',
            'value' => array('bergen|coordinates', 'norway|coordinates'),
            'compare' => 'IN',
        )
    )
);

No problem, deadline in 2 days :)
Thank you, thats really helpful!
I'll try it out. Hopefully it just does the magic!

On Nov 9, 2012, at 12:58 PM, Julien Béchade notifications@github.com wrote:

Sorry for the late answer…

The value is NOT an array, it becomes an array when requested on client-side.
The value is saved in your database as a simple string:

address|coordinates
So perhaps this could work:

$args = array(
'post_type' => 'venue',
'meta_query' => array(
array(
'key' => 'city',
'value' => array('bergen|coordinates', 'norway|coordinates'),
'compare' => 'IN',
)
)
);


Reply to this email directly or view it on GitHub.

Answered just on time then…

Let me know if this works. Haven't use this field with meta_query yet.

Cheers.

Hi, guess I'm a bit late to. I went for another solution I had already set up, so I haven't had a chance to try this out. But thanks for your help!

Glad you solved your problem.