Pages as archive for custom post types with custom categories
-
I have a custom post type “portfolio” with custom categories such as “collaborations, education, etc” and I’m trying to use pages instead of the archive template for an “all projects” page (permalink “portfolio”) with child pages for each category (collaboration, education, etc).
– The page “all projects” displays correctly:
sitename.com/portfolio
– The child pages (collaboration, education, etc) display a 404 page or a blank white screen:
sitename.com/portfolio/education
– The single custom post type posts display correctly with the correct permalink:
sitename.com/portfolio/education/single-post-name
My custom post-type settings are:rewrite' => array( 'slug' => 'portfolio/%custom_cat%', 'with_front' => true ), 'has_archive' => false, 'hierarchical' => false,
My custom taxonomy settings are:
'has_archive' => false, 'rewrite' => array('slug' => 'portfolio/custom_cat', 'with_front' => true),
And I have a function:
function wpa_show_permalinks( $post_link, $post ){ if ( is_object( $post ) && $post->post_type == 'cpt_projects' ){ $terms = wp_get_object_terms( $post->ID, 'custom_cat' ); if( $terms ){ return str_replace( '%custom_cat%' , $terms[0]->slug , $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
I’m trying to figure out how to get the child pages to work properly. Any help would be greatly appreciated!
- The topic ‘Pages as archive for custom post types with custom categories’ is closed to new replies.