0
我在获取acf内容以在Wordpress循环中显示时遇到了一些问题。 我使用page.php文件模板中的代码如下:高级自定义字段内容不显示在wordpress循环中
<?php $args = array (
'post_type' => 'test-box'
);
$the_query = new wp_query ($args);
?>
<?php if (have_posts()) : while ($the_query->have_posts()) : $the_query- >the_post(); ?>
<?php
the_field('acf_test_box_header');
the_field('acf_test_box_content');
?>
<?php endwhile; else : ?>
<p>There are no posts to display.</p>
<?php endif; ?>
的问题是两个领域:当循环中,而不是返回“头acf_test_box_header和acf_test_box_content不显示其内容2“和”内容2“。如果我将它们移到循环之外,那么它们将显示输入正确的内容。
任何想法?
也许尝试这个the_field( 'acf_test_box_header',get_the_ID())? –
你的if语句不正确。 'if($ the_query-> have_posts()):' – CiprianD
没有 - 不会伤心。 – Stef