First of all, query_var
must be true
or a string if you want any sort of front end display to work, whether or not you use pretty permalinks.
The second part is rewrite
has to at least be true
. Note that valid values for rewrite
are either boolean true/false, or an array. This:
$args['rewrite'] = 'my-cool-retailer';
… will enable rewrites, but it won’t set the slug to my-cool-retailer
, because a string is not a valid value here, it just gets interpreted as true
, and your slug will be wc_product_retailer
.
If you want to set a different slug, you need to make rewrite
an array with key slug
:
$args['rewrite']['slug'] = 'my-cool-retailer';
As for has_archive
, that’s true
by default, so that works without changing anything but query_var
. You can also pass a string if you want something other than wc_product_retailer
to be the archive slug.
So, using your first code block and then setting those two values in the filter works for me when I test on a default install:
function change_post_types_slug( $args, $post_type ) {
if ( 'wc_product_retailer' === $post_type ) {
$args['query_var'] = true;
$args['rewrite']['slug'] = 'my-cool-retailer';
}
return $args;
}
add_filter( 'register_post_type_args', 'change_post_types_slug', 10, 2 );
One other thing you may want to add is with_front
, which is true
by default. This will add any static prefix from your post
permalink to your CPT, which is usually not desirable.
$args['rewrite']['with_front'] = false;