Custom taxonomy in URL showing 404

Using a custom post type with custom taxonomy I’m after a custom url structure of /post-type/custom-taxonomy/article-name.

I’ve searched and read up on Permalinks: custom post type -> custom taxonomy -> post and How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name (and a bunch of others, mainly these) but I’m still having issues that I can’t find an answer to.

Custom post type and taxonomy work fine, the url is showing how I want it when I click through to the post, but instead of my post I’m getting a 404 error. I’ve gone into permalinks and saved a million times, still getting that 404.

First of all I’m registering the taxonomy:

register_taxonomy( ‘mediacentral_type’,
array(‘ssd-mediacentral’),
array(‘hierarchical’ => true,
‘labels’ => array(
‘name’ => __( ‘Categories’, ‘ssd’ ),
‘singular_name’ => __( ‘Category’, ‘ssd’ ),
‘search_items’ => __( ‘Search Categories’, ‘ssd’ ),
‘all_items’ => __( ‘All Categories’, ‘ssd’ ),
‘parent_item’ => __( ‘Parent Category’, ‘ssd’ ),
‘parent_item_colon’ => __( ‘Parent Category:’, ‘ssd’ ),
‘edit_item’ => __( ‘Edit Categories’, ‘ssd’ ),
‘update_item’ => __( ‘Update Category’, ‘ssd’ ),
‘add_new_item’ => __( ‘Add New Category’, ‘ssd’ ),
‘new_item_name’ => __( ‘New Post Category’, ‘ssd’ )
),
‘show_admin_column’ => true,
‘show_ui’ => true,
‘public’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘media-central’, ‘with_front’ => false ),
)
);

Then tags,

Then the post type:

register_post_type( ‘ssd-mediacentral’,
array( ‘labels’ => array(
‘name’ => __( ‘Media Central’, ‘ssd’ ),
‘singular_name’ => __( ‘Post’, ‘ssd’ ),
‘all_items’ => __( ‘All Posts’, ‘ssd’ ),
‘add_new’ => __( ‘Add New Post’, ‘ssd’ ),
‘add_new_item’ => __( ‘Add Post’, ‘ssd’ ),
‘edit’ => __( ‘Edit’, ‘ssd’ ),
‘edit_item’ => __( ‘Edit Post’, ‘ssd’ ),
‘new_item’ => __( ‘New Post’, ‘ssd’ ),
‘view_item’ => __( ‘View Post’, ‘ssd’ ),
‘search_items’ => __( ‘Search Posts’, ‘ssd’ ),
‘not_found’ => __( ‘Nothing found in the Database.’, ‘ssd’ ),
‘not_found_in_trash’ => __( ‘Nothing found in Trash’, ‘ssd’ ),
‘parent_item_colon’ => ”
),
‘description’ => __( ‘SSD Media Central Posts’, ‘ssd’ ),
‘public’ => true,
‘publicly_queryable’ => true,
‘exclude_from_search’ => false,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_position’ => 8,
‘menu_icon’ => get_stylesheet_directory_uri() . ‘/library/images/custom-post-icon.png’,
‘rewrite’ => array( ‘slug’ => ‘media-central/%mc_type%’, ‘with_front’ => false ),
‘has_archive’ => ‘media-central’,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
‘supports’ => array( ‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘sticky’)
)
);

Then the filter:

function wpa_mc_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == ‘ssd-mediacentral’ ){
$terms = wp_get_object_terms( $post->ID, ‘mediacentral_type’ );
if( $terms ){
return str_replace( ‘%mc_type%’ , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( ‘post_type_link’, ‘wpa_mc_permalinks’, 1, 2 );

Now when I go to my posts page /media-central and click on a post named ‘test-podcast’ it goes to the URL /media-central/podcasts/test-podcast but I get a 404. Not sure why this is showing a 404 and I’m on the verge of just dropping it, any help would be appreciated.

Read more here:: Custom taxonomy in URL showing 404

Leave a Reply

Your email address will not be published. Required fields are marked *