• 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!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your rewrites conflict, only one or the other can work, the second will be ignored. Ideally, taxonomy permalinks would have some URL element that distinguishes it from portfolio requests. For example /portfolio-cat/education/.

    If you really need /portfolio/education/ to work, try adding a custom rewrite rule that matches ^portfolio/(.*)/?$, i.e. a two element only permalink. That regexp is just an example and likely needs refinement. Three element links like /portfolio/education/single-post-name/ will still be matched by the current rewrite rule. What you cannot do then is have requests like /portfolio/single-post-name/ because WP will try to make it into a taxonomy term archive request.

Viewing 1 replies (of 1 total)
  • The topic ‘Pages as archive for custom post types with custom categories’ is closed to new replies.