Jack Nicholson Jack Nicholson - 1 month ago 16
PHP Question

Multiple Slugs for single Custom Post Type

I'm trying to get a single custom post type to have multiple archive slugs.

Current rewrite:

'rewrite' => array('slug' => 'blog/authors', 'with_front' => false ),


I'm looking to have multiple listings under the same CPT. I'm looking for this sort of functionality:

'rewrite' => array('slug' => array('blog/authors', 'our-people'), 'with_front' => false ),


Is this possible? I am currently assuming I'm going to have to write some custom rewrite rules although I was hoping for a clean solution.

From my searching I found these links but none are helpful for my situation:

https://premium.wpmudev.org/forums/topic/custom-post-type-with-multiple-slugs
Not helpful

https://wordpress.org/support/topic/multiple-rewrite-slugs-for-one-post-type
No fix

Wordpress multiple slugs for a Custom Post Type
Language specific.

Thanks

Answer

You can rewrite the post type url on page load after checking the URL using a hook:

register_post_type( 
    'products', 
    array (
        'rewrite' => array (
            'slug' => _x( 'products', 'URL slug', 'your_text_domain' )
        )
    )
);
Comments