我试图查询ACF字段“show_on_frontpage”值等于“是”(请参阅下面屏幕截图中此字段的定义)的帖子。作为ACF docs规定,这里是我的代码:高级自定义字段:无法通过自定义字段查询帖子
$args = array(
'posts_per_page' => -1,
'meta_key' => 'show_on_frontpage',
'meta_value' => 'yes'
);
$my_posts = new WP_Query($args);
if ($my_posts->have_posts()) {
while ($my_posts->have_posts()) : $my_posts->the_post();
if (get_field('show_on_frontpage')) the_field('show_on_frontpage'); ?>
endwhile;
}
这将返回/无显示。如果我简单地使用$args = array('posts_per_page' => -1);
,那么我会得到我所有的帖子,并且对于那些具有“yes”作为其“show_on_frontpage”字段的值的用户,会显示“yes”。
我的代码有什么问题?
您的报价代码块2号线缺少一个逗号 - 这只是一个转录错误? – DavidCara
更正,谢谢。这不是问题虽然;) – drake035