0

I have a Custom Post Type (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 tried 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 the 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 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' );

1 Answer 1

1

You can't use the slug careers as a page slug as it's already in use as the CPT name. /careers is your post types archive, that is why it's loaded archive.php and not page.php.

Even if you did have a page with that slug, the archive rewrite rule has a higher priority. You'll also find it in the generated sitemap, and the /careers slug is also used to generate the permalinks for individual posts of that type.

The closest you can get is turning off the archive.

I tried to force the template by selecting a custom page template but that didn't help.

This doesn't work because the page is never what is being displayed to begin with. WordPress believes based on the main query it is on an archive of posts of type careers and will behave according to the standard template hierarchy, choosing the most specific template it can find that matches. E.g. if archive-careers.php was available it would have loaded that instead.

Remember, the template chosen is determined by the parameters of the main query. WordPress didn't load a page because you were on page.php, it's the other way round, it loaded page.php because the main query said it was for a page, and it may decide to load a custom page template if that page in the query specifies one. But if it's an archive that doesn't happen. Look at the template hierarchy for more details.

Or even with the help of Elementor pro?

If you want to style that archive using Elementor, then you will need to contact Elementor support or post in an Elementor community. 3rd party plugin dev support is off topic here and not in this stacks scope.

2
  • Hey Tom, not trying to get Elementor support here, maybe my I wasn't clear enough but you did answer my question about the slugs uniqueness, so thanks :D
    – hnnnng
    Mar 4, 2022 at 2:23
  • Here's a very useful link to understand wphierarchy.com Mar 4, 2022 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.