I am using "Video" theme for my wordpress website. In this theme, videos post type and "videoscategory" taxonomy are defined. Here is the register code for taxonomy:
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
)
);
}
I added some categories under videoscategory taxonomy. Now i want to get all the categories that belongs to videoscategory. I googled the whole day, and I use
$tax_terms =get_terms('videoscategory');
but get empty array. Does anyone know what is the problem? thanks.
There is an example in the codex when you visit the
get_terms
pageJust a tip: objects created under a custom taxonomy is called terms, not categories. Please see this post I've done on WPSE
Here's an example for you that I used for a FAQ post type:
and I created the post type like this:
Here is use this code, you definitely find your solution