0

I have a Custom Post Type called Whatever.

The slug for this CPT is whatever.

By default, I can access the posts archive in the frontend at /whatever and each post at /whatever/post-slug

But I would like to have a landing page for this section, which should be accessed at /whatever.

This would collide with the archive, and hence, I want to move the archive to be accessed at /whatever/results.

Briefing up:

I need to have a structure as follows:

/whatever (normal page with a slug set to whatever)
/whatever/results (archive for the whatever custom post type)
/whatever/post-slug (single post inside the whatever custom post type)

When registering the CPT, I can pass as an arg:

'rewrite' => ['slug' => 'whatever', 'with_front' => true],

But here, I need to have a subfolder, and doing:

'rewrite' => ['slug' => 'whatever/result', 'with_front' => true],

Doesn't work.

4
  • it doesn't have to collide, this looks like your solution to the collision problem, was there a reason you didn't ask about that instead? With the right changes a page at whatever/ is possible, with multiple methods to do it with pros and cons
    – Tom J Nowell
    Nov 23, 2022 at 12:49
  • @TomJNowell Thanks for helping. But, how can I have a landing page accessible at /whatever and also an archive page at the same URL without them colliding? Nov 23, 2022 at 12:52
  • ah I misunderstood
    – Tom J Nowell
    Nov 23, 2022 at 12:55
  • @TomJNowell All cool, thanks for helping! Nov 23, 2022 at 12:56

1 Answer 1

1

You can have a different slug for the archive by setting has_archive to a string:

register_post_type(
    'whatever',
    array(
        'has_archive' => 'whatever/results',
        'rewrite'     => array(
            'slug' => 'whatever',
        ),
        // ...etc.
    )
);

I've tested that and it seems to do exactly what you needed.

1
  • Works like a charm. WP never ceases to amaze. Nov 24, 2022 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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