我對我的wordpress網站使用「視頻」主題。在這個主題中,定義了視頻文章類型和「視頻類別」分類。這裏是分類的註冊碼:wordpress獲得自定義帖子類型的分類列表
add_action("init", "custom_posttype_menu_wp_admin1");
function custom_posttype_menu_wp_admin1()
{
register_post_type('videos',
array('label' => __('Videos','templatic'),
'labels' => array( 'name' => __('Video','templatic'),
'singular_name' => __('Video','templatic'),
'add_new' => __('Add Video','templatic'),
'add_new_item'=> __('Add New Video','templatic'),
'edit' => __('Edit','templatic'),
'edit_item'=> __('Edit Video','templatic'),
'new_item' => __('New Video','templatic'),
'view_item' => __('View Video','templatic'),
'search_items' => __('Search Videos','templatic'),
'not_found' => __('No Videos found','templatic'),
'not_found_in_trash'=> __('No Videos found in trash','templatic')
),
'public' => true,
'can_export' => true,
'show_ui' => true, // UI in admin panel
'_builtin' => false, // It's a custom post type, not built in
'_edit_link' => 'post.php?post=%d',
'capability_type' => 'post',
'menu_icon' => get_bloginfo('template_url').'/images/favicon.ico',
'hierarchical' => false,
'rewrite' => array("slug" => "videos"), // Permalinks
'query_var' => "videos", // This goes to the WP_Query schema
'supports' => array( 'title',
'author',
'excerpt',
'thumbnail',
'comments',
'editor',
'trackbacks',
'custom-fields',
'revisions') ,
'show_in_nav_menus' => true ,
'taxonomies' => array('videoscategory','videostags')
)
);
// Register custom taxonomy
register_taxonomy( "videoscategory",
array( "videos" ),
array ("hierarchical"=> true,
"label"=> "Category",
'labels'=> array( 'name' => __('Category','templatic'),
'singular_name'=> __('Category','templatic'),
'search_items'=> __('Search Category','templatic'),
'popular_items' => __('Popular Category','templatic'),
'all_items'=> __('All Category','templatic'),
'parent_item' => __('Parent Category','templatic'),
'parent_item_colon' => __('Parent Category:','templatic'),
'edit_item' => __('Edit Category','templatic'),
'update_item'=> __('Update Category','templatic'),
'add_new_item'=> __('Add New Category','templatic'),
'new_item_name'=> __('New Make Category','templatic')),
'public'=> true,
'show_ui' => true,
'query_var'=> true,
"rewrite" => true
)
);
}
我在視頻分類分類下添加了一些類別。現在我想要獲取屬於videoscategory的所有類別。我GOOGLE了一整天,我用
$tax_terms =get_terms('videoscategory');
但得到空陣列。有誰知道這是什麼問題?謝謝。
易於使用得到所有自定義後類型類別:HTTP://wp.m E/p4esuX-3K – 2014-12-31 06:53:16