I’m having some issues with some url structures on my current WP project.

I have a cpt and a page with the same name and URL structure. This obviously generates som issues. Since I have never really worked with the permalink structure of post vs pages I’m asking for some inputs on what choices I have.

I have a page called “ansatte” with a childpage called “bliv-frivillig”.

Meanwhile I have a custom post type called ansatte with “ansatte” as its base url as well.

So when I try to access the “bliv-frivillig” childpage I’m greeted with a 404, since WP is looking for the post.

My dream scenario would be for both the pages and the cpt to share the base slug of “ansatte”. Is this even possible in WP?

Here is my CPT args from functions:

$rewrite = array(
    'slug'                  => 'ansatte',
    'with_front'            => true,
    'pages'                 => false,
    'feeds'                 => false,
);
$args = array(
    'label'                 => __( 'Ansat', 'mydomain' ),
    'description'           => __( 'Ansatte og tilknyttede til Museer', 'mydomain' ),
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'thumbnail', ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 35,
    'menu_icon'             => 'dashicons-groups',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => false,        
    'exclude_from_search'   => true,
    //'with_front'            => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'page',
);

Read more here: cpt and page sharing same base permalink


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: