David Jones David Jones - 1 month ago 4
PHP Question

How to create a custom post type with an archive slug that differs from the post type name

I've created a post type called

and an accompanying archive page
. When I navigate to
, the archive page loads properly. However, I'd like the archive URL to be
. I'm defining the
property below but it doesn't seem to be working. What am I missing?

"menu_icon" => "dashicons-tag",
"labels" => array(
"name" => __( "Listings" ),
"singular_name" => __("Listing")
"public" => true,
"has_archive" => true,
"rewrite" => array("slug" => "marketplace"),
"supports" => array("title", "editor"),
"taxonomies" => array("listing_status")


When you register a new custom post type you need to flush your permalinks.

To do that, go to Settings -> Permalinks in the admin and hit save (no changes are required).

If you're creating something that's going to be distributed you may want to do it programmatically instead. You'd need to run flush_rewrite_rules() by hooking into the plugin activation or after_switch_theme action. Documentation can be found here: https://codex.wordpress.org/Function_Reference/flush_rewrite_rules