I have a plugin that creates a custom post type. However it doesn’t create an archive or make the single posts visible and I would like to change that.
This is the code to register the post type:
private static function init_taxonomy() {
$show_in_menu = current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : $show_in_menu = true;
register_post_type( 'wc_product_retailer',
array(
'labels' => array(
'name' => __( 'Retailers', 'woocommerce-product-retailers' ),
'singular_name' => __( 'Retailer', 'woocommerce-product-retailers' ),
'menu_name' => _x( 'Retailers', 'Admin menu name', 'woocommerce-product-retailers' ),
'add_new' => __( 'Add Retailer', 'woocommerce-product-retailers' ),
'add_new_item' => __( 'Add New Retailer', 'woocommerce-product-retailers' ),
'edit' => __( 'Edit', 'woocommerce-product-retailers' ),
'edit_item' => __( 'Edit Retailer', 'woocommerce-product-retailers' ),
'new_item' => __( 'New Retailer', 'woocommerce-product-retailers' ),
'view' => __( 'View Retailers', 'woocommerce-product-retailers' ),
'view_item' => __( 'View Retailer', 'woocommerce-product-retailers' ),
'search_items' => __( 'Search Retailers', 'woocommerce-product-retailers' ),
'not_found' => __( 'No Retailers found', 'woocommerce-product-retailers' ),
'not_found_in_trash' => __( 'No Retailers found in trash', 'woocommerce-product-retailers' ),
),
'description' => __( 'This is where you can add new product retailers that you can add to products.', 'woocommerce-product-retailers' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'capabilities' => array(
'publish_posts' => 'manage_woocommerce_product_retailers',
'edit_posts' => 'manage_woocommerce_product_retailers',
'edit_others_posts' => 'manage_woocommerce_product_retailers',
'delete_posts' => 'manage_woocommerce_product_retailers',
'delete_others_posts' => 'manage_woocommerce_product_retailers',
'read_private_posts' => 'manage_woocommerce_product_retailers',
'edit_post' => 'manage_woocommerce_product_retailers',
'delete_post' => 'manage_woocommerce_product_retailers',
'read_post' => 'manage_woocommerce_product_retailers',
),
'publicly_queryable' => true,
'exclude_from_search' => true,
'show_in_menu' => $show_in_menu,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array( 'title' ),
'show_in_nav_menus' => false,
)
);
}
This is the code I’m using in my functions.php of my child theme.
function change_post_types_slug( $args, $post_type ) {
/*item post type slug*/
if ( 'wc_product_retailer' === $post_type ) {
$args['has_archive'] = true;
}
return $args;
}
add_filter( 'register_post_type_args', 'change_post_types_slug', 10, 2 );
It doesn’t change anything.
Additionally I’ve tried directly changing the plugin file by adding
'has_archive' => true,
below
'show_in_nav_menus' => false,
and then even changing
show_in_nav_menus
and query_vars
to true.
Setting rewrite
to ‘my-cool-retailer’.
Each of these changes i’ve gone to peramlinks settings and hit save. I’ve even disabled the plugin and re-enabled it.
Also, on the post edit screen it continues to not show the post slug under the title.