我有一个静态页面,里面有一个高级自定义字段(ACF)'转发器'区域,还有一些代码用于引入一些自定义帖子。
我在页面顶部有这段代码。
<?php get_header(); the_post(); query_posts('post_type=team_profiles') ?>
如果这样离开,我会看到我的帖子,但不会看到来自ACF的数据。如果我拿出以下部分:
query_posts('post_type=team_profiles')
我看到了ACF字段,但没有看到帖子数据。
我的问题首先是为什么会发生这种情况,其次是我如何将它们放在同一页面上?
我的静态页面中的ACF和POSTS代码如下:
ACF中继器字段
<?php if( get_field('about_sections') ): ?>
<?php while( has_sub_field('about_sections') ): ?>
<div class="asset image">
<?php the_sub_field('about_section'); ?>
</div> <!-- asset image -->
<?php endwhile; ?>
<?php endif; ?>
帖子
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content-single-team-profile', get_post_format() ); ?>
<?php endwhile; ?>
<?php endif; ?>
答案 0 :(得分:0)
这是因为在调用get_posts()时会覆盖主查询。你可以:
OR
看看这个:http://codex.wordpress.org/Function_Reference/wp_reset_postdata
这些都是简单的解决方案。更复杂和更好的将涉及创建WP_Query对象并迭代它的帖子而不是依赖于全局变量。