custom post types – Why wordpress is picking archive.php instead of page.php?

Question

I have a cpt called “Careers” with “careers” as slug.

I created my Careers listing page with Elementor (the page slug is also “careers”), dropped the Posts widget and used the Query settings to select my Careers cpt. Then I used Elementor again to create a Single post theme for my single careers posts. The single posts are working okay but now when I click back to my Careers listing page, I get the archive page that doesn’t look anything like the page I created with Elementor (I see the page is now using archive.php with Reveal template plugin). I tried to force the template by selecting a custom page template but that didn’t help. I also tryied resetting the Permalinks, that didn’t help either.

When I try to open my Careers page in Elementor, I get the “Preview could not be loaded Error”. When I change the page Url from “careers” to “career” or “open-positions” then the error goes away, I can open the page with Elementor now (with a new slug).

Is this a correct assumption that the cpt slug cannot be the same as page slug? Is there a better way to accomplish this (preferably with the same slug for both the page and the cpt)? Or even with the help of Elementor pro?

This is my simple cpt code:

function create_careers_posttype() {
    register_post_type( 'careers',
        array(
            'labels' => array(
                'name' => __('Careers'),
                'singular_name' => __('Career')
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'careers'),
            'show_in_rest' => true,
            'supports' => array('title', 'page-attributes'),
        )
    );
}
add_action( 'init', 'create_careers_posttype' );

0
hnnnng 5 months 2022-03-03T20:49:11-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse