/ Published in: PHP
Wordpress Custom Post Type, custom taxonomy and queries
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Register the custom post type register_post_type( 'my_custom_type', 'name' => _x('Custom Type Items', 'post type general name'), 'singular_name' => _x('Custom Type', 'post type singular name'), 'add_new' => _x('Add New', 'custom_type'), 'add_new_item' => __('Add New Item'), 'edit_item' => __('Edit Item'), 'new_item' => __('New Item'), 'all_items' => __('All Items'), 'view_item' => __('View item'), 'search_items' => __('Search item'), 'not_found' => __('No items found'), 'not_found_in_trash' => __('No items found in trash'), 'parent_item_colon' => '', 'menu_name' => 'Custom Type', ), 'public' => true, ) ); //Register categories for the custom type 'hierarchical' => true, 'label' => __( 'Categories for Custom Type' ), 'show_ui' => true ) ); $cat = get_terms('my_custom_type_categories'); //All categories for post type $q = new WP_Query (array ('taxonomy'=>'my_custom_type_categories','term'=> $cat->slug)); //Posts from the taxonomy