As per WP documentation,
Using the WP_Meta_Query::parse_query_vars( $query ) method: You can
use this method, if you want to use the simple query args(meta_key
,
meta_value
,meta_type
,meta_compare
), or if you are unsure of
the presence of meta query parameters.
Hence, I tried converting meta_key
, meta_value
and meta_compare
in source code to wrap inside meta_query
as key
, value
, compare
.
Also, added if( $registrations->have_post() ) {
Can you check if below code snippet works for you ?
$events = new WP_Query(Array(
'posts_per_page' => -1,
'post_type' => 'event'
));
if ($events->have_posts()){
while($events->have_posts()){
$events->the_post();
echo "<p>Event " . get_the_title() . '</p>';
$eventID = $events->get_the_ID();
echo $eventID;
$args = array(
'post_type' => 'registration',
'meta_query' => array (
'key' => 'event_id',
'value' => $eventID,
'compare' => '='
)
);
$registrations = new WP_Query($args);
if( $registrations->have_post() ) {
while ($registrations->have_posts()){
$registrations->the_post();
echo "<p>The registrations list " . get_the_title() . "</p>";
}
}
}
}
Edit 1 :
If the event_id
is an ACF then you should try fetching registrations using ACF functions.
Ref: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
echo $eventID;
$registrations = get_posts(array(
'numberposts' => -1,
'post_type' => 'registration',
'meta_query' => array(
array(
'key' => 'event_id',
'value' => $eventID,
'compare' => '=',
),
),
));
if( $registrations->have_post() ) {
while ($registrations->have_posts()){
$registrations->the_post();
echo "<p>The registrations list " . get_the_title() . "</p>";
}
}