我在模板中使用高级自定义字段。循环结束后,字段将不再显示。循环前一切正常
<?php the_field('Text_fisrt_sec'); ?> // the code works
<?php
$args = array(
'post_type' => 'project',
'publish' => true,
'paged' => get_query_var('paged'),
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?>
<h2><?php the_title();?></h2>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
<?php the_field('Text_fisrt_sec'); ?> // Here the code does not work anymore
您应该使用wp_reset_query();
而不是wp_reset_postdata();
<?php $args = array(
'post_type' => 'project',
'publish' => true,
'paged' => get_query_var('paged'),
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
?>
<h2><?php the_title();?></h2>
<?php
endwhile;
endif;
wp_reset_query((;
?>
<?php the_field('Text_fisrt_sec'); ?>