Wordpress自定义Post类型自定义分类法和查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress自定义Post类型自定义分类法和查询相关的知识,希望对你有一定的参考价值。

Wordpress Custom Post Type, custom taxonomy and queries
  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

以上是关于Wordpress自定义Post类型自定义分类法和查询的主要内容,如果未能解决你的问题,请参考以下文章

循环浏览wordpress3.0+自定义post类型分类法

WordPress 自定义帖子类型前端

从 Wordpress 取消注册自定义帖子类型

Wordpress 自定义帖子类型和自定义分类

wordpress自定义分类怎么调用?

Wordpress:使用 post__not_in 排除自定义分类类别