1

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>';
 }
  • 1
    Hi Elena. Yes it is possible, but could you please provide more details on what you've tried already (and why it didn't work)? – kraftner Jul 24 '15 at 13:35
  • To be honest I don't know where to begin :( I have a simple code to display all the terms Name. I insert that code above.. @kraftner – Elena Jul 24 '15 at 14:28
  • Does $term->cognome_nome not work? – s_ha_dum Jul 24 '15 at 14:40
  • unfortunately doesn't work :( – Elena Jul 24 '15 at 14:50
5

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);
}
  • Thank you very much @Nam! Do you even know how can I order the list alphabetically? For example I have: A Daniel, P Andrea, P Elena, Z Carl. I tried the orderby => name but it doesn't work.. – Elena Jul 27 '15 at 12:27
  • It should work, you still use get_terms('authors') to get the terms right? – Nam Jul 28 '15 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.