2017-12-18 227 views
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'), 
)); 
} 

那麼,一切正常,但現在我無法顯示作者。我使用下面的代碼嘗試,但它不工作(只顯示單詞「陣列」):

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

任何人都可以幫助我嗎?

+0

:(((我迷路了,我檢查了WC_Post_types,但我還沒有找到我要找的代碼 – Stefano

+0

哦,是的。 !!!找出解決方案: De'.get_the_term_list($ post-> ID,'autor')''' – Stefano

回答

1

的解決方案是使用get_the_term_list()函數:

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