I have an “About Us” page on my site with some child pages. I have created a “History” custom post type, where the rewrite slug is ‘history’.
I use archive-cpt_history.php as the template file for that CPT. Everything works exactly as its configured, I can go to website.com/history/ to see my CPT loop in all its glory.
The issue is, I need this history CPT to be a child of About Us. How can I rewrite the slug to be /about-us/history so that it works with the archive / landing page? I can do this:
'rewrite' => array( 'slug' => '/about-us/history', 'with_front' => false ),
But that only works with the single posts, not the archive / landing page. Any help would be greatly appreciated.
Also, in case this is relevant, once I have solved this issue single-cpt_history.php will simply use ” header( ‘Location: ‘ . site_url(”) ); ” to redirect users back home. There is never any permalink to the individual History post. The design just doesn’t work like that. The History landing page will always show all posts in the CPT.
In your register post type arguments, set
rewrite
totrue
andhas_archive
to the path you want for the archive page (without leading slash):As for the redirection, rather than getting all the way to the template, you could short-circuit the loading of single posts earlier and remove the need for the single cpt template: