自定义字段 Wordpress 和 foreach
Custom fields Wordpress and foreach
我对 wordpress 中的自定义字段有疑问。
我有子页面:
- 主场PL
- 首页德
- 主页 EN
我已将自定义字段添加到每个子页面,每个子页面在每种语言中都是相同的。
例如
<?php the_field('text1'); ?>
<?php the_field('text2'); ?>
<?php the_field('text3'); ?>
一切正常,直到我添加一个显示该子类别的报价的循环。
例如
$args = array('post_type' => 'page', 'posts_per_page' => -1,
'post_parent' => 44, 'orderby' => 'title', 'order' => 'ASC', );
$parents = get_posts( $args );
foreach ($parents as $post) :
setup_postdata($post);
endforeach;
当您想添加自定义字段时,在循环下方它不起作用。如何解决?
您需要在循环内执行 the_field()。
我对 wordpress 中的自定义字段有疑问。
我有子页面:
- 主场PL
- 首页德
- 主页 EN
我已将自定义字段添加到每个子页面,每个子页面在每种语言中都是相同的。
例如
<?php the_field('text1'); ?>
<?php the_field('text2'); ?>
<?php the_field('text3'); ?>
一切正常,直到我添加一个显示该子类别的报价的循环。
例如
$args = array('post_type' => 'page', 'posts_per_page' => -1,
'post_parent' => 44, 'orderby' => 'title', 'order' => 'ASC', );
$parents = get_posts( $args );
foreach ($parents as $post) :
setup_postdata($post);
endforeach;
当您想添加自定义字段时,在循环下方它不起作用。如何解决?
您需要在循环内执行 the_field()。