I'm struggling with understanding some things about CPTs and and could do with some help. I can see that taxonomies often need to be hierarchical, but can't see how/when a custom post type would be?
i.e I have a CPT called 'projects'. There is a taxonomy registered for this posttype called 'fields'. Under 'fields' I have lots of sub-items like:
- 'Documentaries'
- 'Documentaries' > 'Self Commisions'
- 'Documentaries' > 'Classic'
- 'Corporate'
- 'Corporate' > 'Digital Marketing'
- etc...
So to view a project in 'Documentaries' > 'Classic' I use this URL: mydomain.com/field/classic/
This is where I actually have about 30 questions :) but will just ask the two most pressing:
- Why and how would the 'projects' CPT ever be hierarchical?
- Is it possible to view items in the 'classic' field like so: mydomain.com/projects/classic (mydomain.com/projects shows all items, but drilling any further breaks it)
Any and all help appreciated, I've spent about 3 hours playing with this and reading and can't get my head around it!
Thanks!
Below is my (cropped) code for reference:
function register_cpt_projects() {
$labels = array(
'name' => _x('Projects', 'projects'),
// all other labels etc..
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array('title', 'editor', 'author', 'thumbnail'),
'taxonomies' => array('field'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type('projects', $args);
}
add_action('init', 'register_cpt_projects');
function create_projects_tax(){
register_taxonomy('field', 'projects', array(
'hierarchical' => true,
'label' => 'Fields'
));
}
add_action('init', 'create_projects_tax');