Get custom field values of taxonomy terms

I added a Custom Field named 'cognome_nome' in my Custom Taxonomy named 'authors'. I would like to display in a Archive Page a list of all 'cognome_nome' values of the terms.

Examples:

1.term

  • Name: Elena P
  • slug: elena_p
  • cognome_nome: P Elena

2.term

  • Name: Andrea P
  • slug: andrea_p
  • cognome_nome: P Andrea

I would like to display:

  • P Elena
  • P Andrea

and so on... Do you think it's possible?

Thank you in advance :)

EDIT

I'm using this code to list all the terms:

$terms = get_terms( 'authors' );
 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
     echo '<ul>';
     foreach ( $terms as $term ) {
       echo '<li> <a href="' . get_term_link( $term ) . '">' . $term->name . '</a></li>';

     }
     echo '</ul>';
 }

Answers 1

  • Are you using Advanced Custom Fields plugin? If you are, try this if it works:

    foreach ($terms as $term) {
         // $cognome_nome will be "P Elena" or "P Andrea" in your case
         $cognome_nome = get_field('cognome_nome', $term->taxonomy.'_'.$term->term_id);
    }
    

Related Questions