Your desired URLs:
www.example.com/results/post-name/
www.example.com/results/categories/category-name/
Two changes from your original code:
-
Priority was added to both
add_action
hooks to reverse the order they execute. Order matters in this case, because the post type’s attachment rewrite rules override the taxonomy rewrites. Side-effect: attachment URLs don’t work for this post type! -
Rewrite for the taxonomy was changed to
results/categories
.
// Create custom post type
function create_posttype() {
register_post_type( 'results',
array(
'labels' => array(
'name' => __( 'Results' ),
'singular_name' => __( 'Results' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'results'),
'taxonomies' => array( 'results', 'result-category' ),
)
);
}
// ADDED PRIORITY
add_action( 'init', 'create_posttype', 9 );
//Create category for specific post type
function tr_create_my_taxonomy() {
register_taxonomy(
'results-categories',
'results',
array(
'label' => __( 'Result Categories' ),
// CHANGED SLUG
'rewrite' => array( 'slug' => 'results/categories' ),
'hierarchical' => true,
'has_archive' => true
)
);
}
// ADDED PRIORITY
add_action( 'init', 'tr_create_my_taxonomy', 8 );
Also note that the most specific general template for this will be taxonomy-results-categories.php
, which will fall back to taxonomy.php
, then archive.php
.