Wordpress Custom Post Type, custom taxonomy and queries


/ Published in: PHP
Save to your folder(s)

Wordpress Custom Post Type, custom taxonomy and queries


Copy this code and paste it in your HTML
  1. //Register the custom post type
  2. register_post_type( 'my_custom_type',
  3. 'labels' => array(
  4. 'name' => _x('Custom Type Items', 'post type general name'),
  5. 'singular_name' => _x('Custom Type', 'post type singular name'),
  6. 'add_new' => _x('Add New', 'custom_type'),
  7. 'add_new_item' => __('Add New Item'),
  8. 'edit_item' => __('Edit Item'),
  9. 'new_item' => __('New Item'),
  10. 'all_items' => __('All Items'),
  11. 'view_item' => __('View item'),
  12. 'search_items' => __('Search item'),
  13. 'not_found' => __('No items found'),
  14. 'not_found_in_trash' => __('No items found in trash'),
  15. 'parent_item_colon' => '',
  16. 'menu_name' => 'Custom Type',
  17. ),
  18. 'supports' => array('title'),
  19. 'public' => true,
  20. )
  21. );
  22.  
  23. //Register categories for the custom type
  24. register_taxonomy( 'my_custom_type_categories', 'my_custom_type', array(
  25. 'hierarchical' => true,
  26. 'label' => __( 'Categories for Custom Type' ),
  27. 'show_ui' => true
  28. )
  29. );
  30.  
  31.  
  32. $cat = get_terms('my_custom_type_categories'); //All categories for post type
  33.  
  34. $q = new WP_Query (array ('taxonomy'=>'my_custom_type_categories','term'=> $cat->slug)); //Posts from the taxonomy

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.