ACF: Как получить подполе на странице category.php? - PullRequest
0 голосов
/ 05 февраля 2019

Я создал поля для терминов, используя 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;

}

?>

Но я не получаю результаты, Нужна ваша помощь.Спасибо.

1 Ответ

0 голосов
/ 05 февраля 2019

Я только что проверил следующий код.Используйте следующий код.

<?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/

...