Tested and verified:
I am writting in steps to make it clear:
- Make sure when you registered your custom post type
rewrite
for more: register custom post type
'rewrite' => array('slug' => '/%project_categories%','with_front' => FALSE),
- Then register your taxonomies project_categories
You need to register custom taxonomy project_categories for this custom (project) post type. register_taxonomy
please read here for more
function project_taxonomy() {
register_taxonomy(
'project_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
'project', //post type name
array(
'hierarchical' => true,
'label' => 'project store', //Display name
'query_var' => true,
'rewrite' => array(
'slug' => 'project', // This controls the base slug that will display before each term
'with_front' => false // Don't display the category base before
)
)
);
}
add_action( 'init', 'project_taxonomy');
-
Last make, your post type liks filters.
function filter_post_type_link($link, $post)
{
if ($post->post_type != 'project')
return $link;
if ($cats = get_the_terms($post->ID, 'project_categories'))
$link = str_replace('%project_categories%', array_pop($cats)->slug, $link);
return $link;
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
Note: if you see post not found error. then change your permalink settings to default and save changes. And again set permalink to Post name and it will work.