【发布时间】:2017-08-26 23:48:37
【问题描述】:
我正在尝试查询 ACF 字段“show_on_frontpage”值等于“yes”的帖子(请参阅下面屏幕截图中此字段的定义)。如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);,那么我会得到我所有的帖子,并且对于那些将“是”作为“show_on_frontpage”字段值的人显示“是”。
我的代码有什么问题?
【问题讨论】:
-
引用代码块的第 2 行缺少逗号 - 这只是转录错误吗?
-
已更正,谢谢。但这不是问题;)