我正在尝试将查询中的ACF字段值作为值传递。让我展示一下我现在拥有的:
array(
\'key\' => \'office\', // name of custom field
\'value\' => \'320\', // matches exaclty "123", not just 123. This prevents a match for "1234"
\'compare\' => \'LIKE\'
),
如您所见,我现在有了静态值,这是post对象的ID。问题是,这并不总是“320”,所以我创建了另一个关系来选择您想要的办公室。但现在我对如何将该字段值传递到查询中感到困惑。我尝试了类似的方法,但它返回了所有办公室的所有用户
$valuee = get_field( "choose_office" );
$args = array(
\'meta_query\' => array(
array(
\'key\' => \'office\', // name of custom field
\'value\' => $valuee, // matches exaclty "123", not just 123. This prevents a match for "1234"
\'compare\' => \'LIKE\'
),
),
);
最合适的回答,由SO网友:MR.Don\'t know 整理而成
解决方案:
$posts = get_field(\'choose_office\'); if( $posts ):
foreach(array_slice($posts, 0, 1) as $post):
setup_postdata($post);
$post_ID = get_the_ID();
endforeach;
wp_reset_postdata();
endif;
$args = array(
\'meta_query\' => array(
array(
\'key\' => \'office\', // name of custom field-post object
\'value\' => $post_ID, //name of relationship field
\'compare\' => \'LIKE\'
),
),
);
问题解决方案:
https://stackoverflow.com/questions/46816190/using-post-id-inside-reverse-acf-relationship-querie