显示产品的自定义分类

问题描述 投票:1回答:1

我在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>';

有人可以帮帮我吗?

php wordpress woocommerce display custom-taxonomy
1个回答
1
投票

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

echo '<span>De ' . get_the_term_list( $post->ID, 'autor') . '</span>'
© www.soinside.com 2019 - 2024. All rights reserved.