Support

Account

Home Forums General Issues Taxonomy Term Field in Categories Reply To: Taxonomy Term Field in Categories

  • Those items are fields from a taxonomy. Say you’re wanting to list out the default category taxonomy, you’d need to do something like:

    
     $terms = get_terms( 'category' );
     if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
         echo '<ul>';
         foreach ( $terms as $term ) {
           echo '<li>' . $term->name . '</li>';
            
         }
         echo '</ul>';
     }
    

    That will output the name of all the categories you’ve created. If you want to output your custom field as well you’ll add your get_field() like:

    
     $terms = get_terms( 'category' );
     if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
         echo '<ul>';
         foreach ( $terms as $term ) {
           echo '<li>' . $term->name . ' - ' . get_field('short_description', $term->taxonomy . '_' . $term->term_id) . '</li>';
            
         }
         echo '</ul>';
     }
    

    For the get_field() function you’re passing your field name short_description along with the $term->taxonomy and $term->term_id separated by an underscore.