【发布时间】:2019-02-06 07:56:07
【问题描述】:
我使用 ACF 为术语创建了字段。我还使用以下代码创建了category.php:
<?php
// load all 'category' terms for the post
$terms = get_the_terms( get_the_ID(), 'category' );
// we will use the first term to load ACF data from
if ( !empty( $terms ) ) {
$term = array_pop($terms);
if ( have_rows( 'page_banner' ) ) :
// loop through the rows of data
while ( have_rows( 'page_banner' ) ) : the_row();
$custom_field = get_sub_field( 'small_title', $term );
echo $custom_field;
endwhile;
else :
endif;
}
?>
但我没有得到结果,需要你的帮助。谢谢。
【问题讨论】:
-
get_sub_field() 的第二个参数不是术语。就是格式值,get_sub_field($sub_field_name, $format_value);
-
对不起,我听不懂。你能提供更多细节吗
-
当您调用 get_sub_field() 时,您正在传递 $term。但根据文档,第二个参数应该是 format_value。你可以在这里查看。 advancedcustomfields.com/resources/get_sub_field
标签: wordpress advanced-custom-fields acfpro