获取分类术语的自定义字段值

时间:2015-07-24 作者:Elena

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 个回复
最合适的回答,由SO网友:Nam 整理而成

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);
}
结束

相关推荐