Hi i have managed to get the permalink looking correct now. But when i click it it doesnt show the post. Does anyone have any advice?
Here is the code so far:
add_action( ‘init’, ‘cptui_register_my_cpts’ );
function cptui_register_my_cpts() {
post type
$labels = array(
“name” => “Case Studies”,
“singular_name” => “Case Study”,
);
$args = array(
“labels” => $labels,
“description” => “”,
“public” => true,
“show_ui” => true,
“has_archive” => false,
“show_in_menu” => true,
“exclude_from_search” => false,
“capability_type” => “page”,
“map_meta_cap” => true,
“hierarchical” => false,
“rewrite” => array( “slug” => “%work_type%/case-studies”, “with_front” => true ),
“query_var” => true,
“supports” => array( “title”, “thumbnail”, “page-attributes”, “post-formats” ),
“taxonomies” => array( “work” )
);
register_post_type( “case_studies”, $args );
// End of cptui_register_my_cpts()
}
taxonomy
add_action( ‘init’, ‘cptui_register_my_taxes’ );
function cptui_register_my_taxes() {
$labels = array(
“name” => “Work Type”,
“label” => “Work Type”,
);
$args = array(
“labels” => $labels,
“hierarchical” => false,
“label” => “Work Type”,
“show_ui” => true,
“query_var” => true,
“rewrite” => array( ‘slug’ => ‘%work_type%’, ‘with_front’ => false ),
“show_admin_column” => false,
);
register_taxonomy( “work”, array( “testimonial”, “case_studies” ), $args );
// End cptui_register_my_taxes
}
function to change permalink structure
add_filter(‘post_type_link’, ‘work_permalink_structure’, 10, 4);
function work_permalink_structure($post_link, $post, $leavename, $sample)
{
if ( false !== strpos( $post_link, ‘%work_type%’ ) ) {
$work_type_term = get_the_terms( $post->ID, ‘work’ );
$post_link = str_replace( ‘%work_type%’, array_pop( $work_type_term )->slug, $post_link );
}
return $post_link;
}