根据WP documentation,
Using the WP_Meta_Query::parse_query_vars( $query ) method: 如果要使用简单查询参数,可以使用此方法(meta_key
, meta_value
, meta_type
, meta_compare
), 或者,如果您不确定是否存在元查询参数。
因此,我尝试转换meta_key
, meta_value
和meta_compare
在源代码中进行封装meta_query
像key
, value
, compare
.
此外,添加了if( $registrations->have_post() ) {
您能检查一下下面的代码片段是否适合您吗?
$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>";
}
}
}
}
编辑1:
如果event_id
是ACF,则应尝试使用ACF函数获取注册。
参考号: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>";
}
}