Changing the archive slug independently of single posts
The default slug for a custom post type will match the post type key (first argument of the function). In the example you posted, that would be listing
. You then go on to change it by specifying a new slug under rewrite. That will impact both the single post and the archive however.
To set the archive slug while preserving the regular slug for single posts, you should use has_archive
instead. has_archive
is a misleading name since it accepts either a boolean or a string. Setting it to true will generate the archive page. Passing in a string instead will allow you to customize the slug:
'has_archive' => 'marketplace',
Example in context:
register_post_type( 'listing', [
'menu_icon' => 'dashicons-tag',
'labels' => [
'name' => __( 'Listings' ),
'singular_name' => __( 'Listing' ),
],
'public' => true,
'has_archive' => 'marketplace',
'supports' => [ 'title', 'editor' ],
'taxonomies' => [ 'listing_status' ],
]);
Flushing permalinks
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