Home › Forums › Front-end Issues › Get posts where meta_query Google Map address['street_name'] is…
Hi there,
I have a custom post type for events and every event has an address value from ACF Google Map. on the Single page I get the street name from
$eventlocation = get_field(“eventlocation”);
echo $eventlocation[‘street_name’];
I have a WP_query which lists all events. I set a conditional meta_query if a date if provided in the query string, but I want to add a location filter to the same WP_query if the location matches the street name in $eventlocation[‘street_name’]
<?php
$date_from_url = strtotime(htmlspecialchars($_GET["date"]));
$to_date_object = date('Ymd', $date_from_url);
$meta_query = array();
if (isset($_GET["date"])) {
$meta_query[] = array(
array(
'key' => 'startdate',
'compare' => '=',
'value' => $to_date_object
)
);
} else {
$meta_query[] = array(
array(
'key' => 'startdate',
'compare' => 'EXISTS'
)
);
}
$args = array(
'post_type' => 'activiteit',
'post_status' => 'publish',
'meta_key' => 'startdate',
'orderby' => 'meta_value',
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => $meta_query,
);
$result = new WP_Query($args);
// html here
wp_reset_postdata();
?>
I don’t know how to compare the ‘meta_key’ => ‘eventlocation’ to a sub value of the array…
Thanks for the help…
Got it to work by
$meta_query[] = array(
array(
'key' => 'eventlocation',
'value' => $_GET["location"],
'compare' => 'LIKE',
),
);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.