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

You can also use:

'has_archive' => 'marketplace'

That way the slug of the archive page will be /marketplace and the single page will be /listing


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

Tags:

Php

Wordpress