如何对自定义帖子类型进行分类

时间:2014-12-22 12:29:00

标签: php wordpress

我的问题是自定义帖子类型,其中包含用于对其进行分类的字段。我无法找到解决问题的方法,所以我希望有人可以帮助我。

自定义帖子类型被称为“TEAM”并且需要具有类别“STAFF”“GUESTS”&的滚动列表菜单。 “艺术家”。我已经阅读了很多关于自定义分类法的内容,但我真的没有得到它。

2 个答案:

答案 0 :(得分:2)

function register_team_post_type() {
  $labels = array(
    'name' => 'Team',
    'singular_name' => 'Team',
    'add_new' => 'Add New Team',
    'add_new_item' => 'Add New Team',
    'edit_item' => 'Edit Team',
    'new_item' => 'New Team',
    'all_items' => 'All Team Post',
    'view_item' => 'View Team',
    'search_items' => 'Search Team',
    'not_found' =>  'No Team  found',
    'not_found_in_trash' => 'No Team found in Trash', 
    'parent_item_colon' => '',
    'menu_name' => 'Team Post'
  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => (is_super_admin()) ? true : false, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'team' ),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => 6,
    //'taxonomies' => array('category'), 
    'supports' => array( 'title', 'editor', 'author', 'custom-fields', 'comments' )


  ); 
   register_post_type( 'team', $args );
}
add_action( 'init', 'register_team_post_type' );

add_action( 'init', 'register_team_category', 0 );

function register_team_category() {
    register_taxonomy( 'categories', 'team', array( 'hierarchical' => true, 'label' => 'Team Categories', 'query_var' => true, 'rewrite' => true ) );
}

答案 1 :(得分:0)

尝试使用此代码

    $args = array( 'cat' => '1,2,3', 'post_type' => 'team', 'posts_per_page' => -1 );
    $loop = new WP_Query( $args );      
    while ( $loop->have_posts() ) : $loop->the_post();  
         //do what you want;
    endwhile; 
    // end of the loop. ?>