显示产品的自定义分类

Display a custom taxonomy of a product

我在 woocommerce 中为我的产品创建了自定义分类法。这是我书店作者的非等级分类法。分类法的代码是这样的:

add_action( 'init', 'create_autor_nonhierarchical_taxonomy', 0 );
function create_autor_nonhierarchical_taxonomy() {
// Labels part for the GUI
  $labels = array(
    'name' => _x( 'Autor', 'taxonomy general name' ),
    'singular_name' => _x( 'Autor', 'taxonomy singular name' ),
    'search_items' =>  __( 'Buscar autores' ),
    'popular_items' => __( 'Autores populares' ),
    'all_items' => __( 'Todos los autores' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Editar autor' ), 
    'update_item' => __( 'Actualizar autor' ),
    'add_new_item' => __( 'Añadir nuevo autor' ),
    'new_item_name' => __( 'Nombre del nuevo autor' ),
    'separate_items_with_commas' => __( 'Separa los autores con comas' ),
    'add_or_remove_items' => __( 'Añadir o eliminar autores' ),
    'choose_from_most_used' => __( 'Elije ente los autores más utilizados' ),
    'menu_name' => __( 'Autor' ),
  ); 

// Now register the non-hierarchical taxonomy like tag

  register_taxonomy('autor','product',array(
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'autor' ),
  ));
}

嗯,一切正常,但现在我无法显示作者。我正在尝试使用以下代码,但它不起作用(它只显示单词 "array"):

echo '<span>De '.get_the_terms($post->ID ,'autor').'</span>';

有人能帮帮我吗?

解决方案是使用 get_the_term_list() 函数代替:

echo '<span>De ' . get_the_term_list( $post->ID, 'autor') . '</span>'