输出模板中的帖子是为了防止它下面的标签回声


Outputting the posts in a template is preventing tags below it to echo

<?php
$wpb_all_query = new WP_Query(
     array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1)
);
if ( $wpb_all_query->have_posts() ) : ?>
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
        $cats = get_the_category();
        if ($cats[0]->cat_name === 'Coaching') { ?>
            <div class="callout horizontal">
                <?php the_post_thumbnail() ?>
                <div class="content">
                    <h5><?php the_title(); ?></h5>
                    <?php the_content(); ?>
                </div>
            </div>
        <?php } ?>
    <?php endwhile; ?>
<?php endif; ?>

删除上述代码后,可以运行此<?php echo get_field('column_two'); ?>代码。

我的问题很简单,为什么上面的代码阻止了我的<?php echo get_field('column_two'); ?> 的回显

如果您正在尝试get_field('column_two'(;在while循环中,WordPress会在帖子中查找自定义字段column_two,但这似乎出现在页面中,而不是帖子中。

如果您正在尝试访问get_field('column_wo'(;while循环后,需要重置post数据wpreset_postdata((;请参见此处:https://codex.wordpress.org/Function_Reference/wp_reset_postdata

希望这会有所帮助。