WordPress 5.8 custom post type > rewrite slug 404 error

Viewed 272

I've created a custom post type which uses child pages. See code below. I'm trying to remove the base slug from the URL using: 'rewrite' => array('slug'=> '/','with_front' => false,)

But this gives my other normal pages a 404 error. Anyone an idea how to safely remove the base slug from the URL for multiple custom post types? There are many solutions online which claim to work but those are form 10 years ago. None of these have seem to work for me yet.

Yes, I've tried saving the permalinks many times

current: mydomain.com/cpt/parent/child

wanted: mydomain.com/parent/child

custom post type:

function my_custom_post_product() {
    $labels = array(
      'name'               => _x( 'Products', 'post type general name' ),
      'singular_name'      => _x( 'Product', 'post type singular name' ),
      'add_new'            => _x( 'Add New', 'book' ),
      'add_new_item'       => __( 'Add New Product' ),
      'edit_item'          => __( 'Edit Product' ),
      'new_item'           => __( 'New Product' ),
      'all_items'          => __( 'All Products' ),
      'view_item'          => __( 'View Product' ),
      'search_items'       => __( 'Search Products' ),
      'not_found'          => __( 'No products found' ),
      'not_found_in_trash' => __( 'No products found in the Trash' ),
      'menu_name'          => 'Products'
    );
    $args = array(
        'hierarchical' => true,
        'public' => true,
        'rewrite' => array(
            'slug'       => '/',
            'with_front' => false,
        ),
        'supports' => array(
            'page-attributes',
            'title',
            'editor',
        ),
    );
    register_post_type( 'product', $args ); 
  }
  add_action( 'init', 'my_custom_post_product' );
0 Answers
Related