I figured this out by reading this article. It was very simple, all I had to do was:
- Change the
$talks_cat_args[rewrite][slug]
from'talks'
to'talks/category'
(which I had tried before) but missed… - Make sure
register_taxonomy
is beforeregister_post_type
.
Read the article, but it’s basically because of “how WP_Rewrite works as the process of deciphering permalinks is, in a way, top-down”
For posterities sake here is the final code (with a little reformatting). I can’t argue that this is the best or cleanest way to do this, cause I’m pretty new to WordPress & PHP, but it’s working thus-far.
$talks_labels = array(
'name' => 'Talks',
'singular_name' => 'Talk',
'all_items' => 'All Talks',
'add_new' => 'Add new',
'add_new_item' => 'Add new Talk',
'edit_item' => 'Edit Talk',
'new_item' => 'New Talk',
'view_item' => 'View Talk',
'search_items' => 'Search Talks',
'not_found' => 'No Talks found',
'not_found_in_trash' => 'No Talks found in Trash',
);
$talks_args = array(
'labels' => $talks_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'menu_position' => 5,
'rewrite' => array( 'slug' => 'talks', 'with_front' => false ),
'has_archive' => 'talks',
);
$talks_cat_labels= array(
'name' => 'Talk categories',
'singular_name' => 'Talk category',
'search_items' => 'Search talk categories',
'all_items' => 'All talk categories',
'parent_item' => 'Parent talk category',
'parent_item_colon' => 'Parent talk category:',
'edit_item' => 'Edit talk category',
'update_item' => 'Update talk category',
'add_new_item' => 'Add new talk category',
'new_item_name' => 'New talk category name',
);
$talks_cat_args = array(
'hierarchical' => true,
'labels' => $talks_cat_labels,
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'talks/category',
'with_front' => false
),
);
register_taxonomy( 'uc_talks_cat', array('uc_talks'), $talks_cat_args );
register_post_type( 'uc_talks', $talks_args );