
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',
),
);