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


How to categorize Custom Post Types

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

自定义帖子类型称为"团队",需要一个滚动菜单,其中包含"员工"客人"和"艺术家"类别。我已经阅读了很多关于自定义分类法的信息,但我真的不明白。

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 ) );
}

尝试使用此代码

    $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. ?>