duanrong0738 2017-12-18 12:47
浏览 261
已采纳

显示产品的自定义分类

I've create a custom taxonomy for my products in woocommerce. It's the not hierarchical taxonomy of the authors of my bookstore. The code for the taxonomy is this:

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' ),
  ));
}

Well, everything works perfectly but now I'm not able to display the author. I'm trying using the following code but it doesn't work (it displays only the word "array"):

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

Anyone could help me?

  • 写回答

1条回答 默认 最新

  • dousou1878 2017-12-21 21:40
    关注

    The solution is using get_the_term_list() function instead:

    echo '<span>De ' . get_the_term_list( $post->ID, 'autor') . '</span>'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?