Hi,
I have two CPTs (Events, Drivers) and ‘Events’ has a custom taxonomy of ‘Seasons’.
In my Events CPT I have a repeater for ‘driverresults’ with a relationship sub-field of ‘driver’.
I’m trying to query all events, within a specific season, and also add a meta query to specify the driver.
My query is as follows:
<?php
/* Loop through events in this season and find any results fields where this driver is listed */
$args = array(
'post_type' => 'events',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'seasons',
'field' => 'id',
'terms' => "2",
),
),
'meta_query' => array(
array(
'key' => 'driverresults_%_driver', // name of custom field
'value' => "126",
'compare' => 'LIKE'
),
),
);
$season_events = new WP_Query($args);
if($season_events->have_posts()) : // If this driver has events in the current season
while($season_events->have_posts()) : $season_events->the_post(); ?>
Event!
<?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
Removing the meta_query returns post data but when the meta_query is there the returned posts are empty.
I’ve been trying to get this working for a few hours and having looked through other posts, this seems like it should be working?
Any help would be much appreciated.
Thanks,