显示产品的自定义分类

时间:2017-12-18 12:47:07

标签: php wordpress woocommerce display custom-taxonomy

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

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

解决方案是使用file_groups <- ls()[grep(".*_.*", ls())] file_groups <- gsub("(.*)_.*", "\\1", file_groups) df_list <- lapply(file_groups, function(x){ do.call(rbind, mget(ls(pattern = paste0(x, "*"))))}) 函数:

get_the_term_list()