ACF:如何获得category.php页子场?

问题描述 投票:0回答:1

我创建领域使用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;

}

?>

但我没有得到结果,需要你的帮助。谢谢。

wordpress advanced-custom-fields acfpro
1个回答
2
投票

我只是检查下面的代码。使用下面的代码。

<?php

// get the current taxonomy term
$term = get_queried_object();

if ( have_rows( 'page_banner', $term ) ) {
    while( have_rows( 'page_banner', $term ) ) {
        the_row();
        the_sub_field( 'small_title' );
        echo '<br />';
    }
}

参考

https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/ https://www.advancedcustomfields.com/resources/have_rows/

© www.soinside.com 2019 - 2024. All rights reserved.