I learnt to add multiple custom post types via functions.php
in an array, like this:
add_action('init', 'all_custom_post_types');
function all_custom_post_types() {
$types = array(
array('the_type' => 'event',
'single' => 'Event',
'plural' => 'Events'
),
array('the_type' => 'resource',
'single' => 'Resource',
'plural' => 'Resources'
),
array('the_type' => 'team',
'single' => 'Team',
'plural' => 'Team'
),
);
All well and good, and the options for these post types can be declared as follows:
foreach ($types as $type) {
$the_type = $type['the_type'];
$single = $type['single'];
$plural = $type['plural'];
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($single, 'post type singular name'),
'add_new' => _x('Add New', $single),
'add_new_item' => __('Add New '. $single),
'edit_item' => __('Edit '.$single),
'new_item' => __('New '.$single),
'view_item' => __('View '.$single),
'search_items' => __('Search '.$plural),
'not_found' => __('No '.$plural.' found'),
'not_found_in_trash' => __('No '.$plural.' found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'with_front' => false
),
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'menu_position' => 5,
'supports' => array('title','editor','author'),
'show_in_menu' => true,
'show_in_nav_menus' => true,
'taxonomies' => array( 'category', 'post_tag' ),
);
register_post_type($the_type, $args);
}
}
But what if I want the taxonomies => array( 'category', 'post_tag' ),
line to apply to the resource
post type only? In this instance I'd like to enable taxonomies as follows:
resource
: categories AND tagsevent
: tags ONLYteam
: no taxonomy terms
Can this be done the way I've declared my custom post types, or should I be declaring them separately to achieve more granular control?