0

I have created fields for terms using ACF. I have also created category.php using the below code:

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

}

?>

But I am not getting the results, Need your help. Thank you.

Kashif Rafique
  • 1,273
  • 1
  • 12
  • 25

1 Answers1

2

I just checked the following code. Use the following code.

<?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 />';
    }
}

Reference

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

Sagar Bahadur Tamang
  • 2,670
  • 2
  • 24
  • 41