GET_TERMS不返回任何自定义分类

时间:2013-03-12 作者:user1605942

我有一个自定义的帖子类型,叫做project 调用自定义分类法tagportfolio
我使用此代码生成以下两个:

 add_action(\'init\', \'project_custom_init\');    

/*-- Custom Post Init Begin --*/  
function project_custom_init()  
{  
  $labels = array(  
  \'name\' => _x(\'Projects\', \'post type general name\'),  
  \'singular_name\' => _x(\'Project\', \'post type singular name\'),  
  \'add_new\' => _x(\'Add New\', \'project\'),  
  \'add_new_item\' => __(\'Add New Project\'),  
  \'edit_item\' => __(\'Edit Project\'),  
  \'new_item\' => __(\'New Project\'),  
  \'view_item\' => __(\'View Project\'),  
  \'search_items\' => __(\'Search Projects\'),  
  \'not_found\' =>  __(\'No projects found\'),  
  \'not_found_in_trash\' => __(\'No projects found in Trash\'),  
  \'parent_item_colon\' => \'\',  
  \'menu_name\' => \'Project\'  
);  

$args = array(  
  \'labels\' => $labels,  
  \'public\' => true,  
  \'publicly_queryable\' => true,  
  \'show_ui\' => true,  
  \'show_in_menu\' => true,  
  \'query_var\' => true,  
  \'rewrite\' => true,  
  \'capability_type\' => \'post\',  
  \'has_archive\' => true,  
  \'hierarchical\' => false,  
  \'menu_position\' => null,  
  \'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'comments\')  
);  

// The following is the main step where we register the post.  
register_post_type(\'project\',$args);  

// Initialize New Taxonomy Labels  
$labels = array(  
  \'name\' => _x( \'Tags\', \'taxonomy general name\' ),  
  \'singular_name\' => _x( \'Tag\', \'taxonomy singular name\' ),  
  \'search_items\' =>  __( \'Search Types\' ),  
  \'all_items\' => __( \'All Tags\' ),  
  \'parent_item\' => __( \'Parent Tag\' ),  
  \'parent_item_colon\' => __( \'Parent Tag:\' ),  
  \'edit_item\' => __( \'Edit Tags\' ),  
  \'update_item\' => __( \'Update Tag\' ),  
  \'add_new_item\' => __( \'Add New Tag\' ),  
  \'new_item_name\' => __( \'New Tag Name\' ),  
);  

// Custom taxonomy for Project Tags  
register_taxonomy(\'tagportfolio\',array(\'project\'), array(  
  \'hierarchical\' => true,  
  \'labels\' => $labels,  
  \'show_ui\' => true,  
  \'query_var\' => true,  
  \'rewrite\' => array( \'slug\' => \'tag-portfolio\' ),  
));  

}  
/*-- Custom Post Init Ends --*/      
但是当我使用get_terms() 函数它没有显示任何分类

然后使用以下功能:

get_terms("tagportfolio",array(\'hide_empty\'=>0));
它也没有显示我的任何分类法

1 个回复
SO网友:Дмитрий Шевчук

您有旧版本功能(get_terms($tax, $args);). 尝试以下操作:

get_terms(array(\'hide_empty\'=>0,\'taxonomy\'=>array(\'tagportfolio\')));

结束

相关推荐

发布次数超过x的GET_TERMS

有没有关于get\\u terms的论点,我可以获取与它相关联的只有2篇帖子才有发言权的术语我有一个术语页面,其中列出了我对“艺术家”的所有术语,该页面很大,但很多术语只有一篇文章,因此我只想显示重要的术语。