• Hello

    I would like to use the same slug for a custom post type and its dedicated custom taxonomy. Bug i have 404 page on single post display and pagination (starting to second page) for taxonomy post loop.
    …/books/ works fine
    …/books/%post-title%/ doesn’t work
    …/books/%sectors%/ works
    …/books/%sectors%/page/x/ doesn’t work

    Here is my code. Thanks if you can help me and tell me if this type of rewrite is possible.

    add_action( 'init', 'create_sectors_taxonomies', 0 );
    function create_sectors_taxonomies() {
      $labels = array(
        'name' => 'Secteurs',
        'singular_name' => 'Secteur',
        'search_items' =>  'Recherche secteur',
        'all_items' => 'Tous les secteurs',
        'parent_item' => 'Secteur parent',
        'parent_item_colon' => 'Secteur parent:',
        'edit_item' => 'Editer secteur',
        'update_item' => 'Mettre à jour le secteur',
        'add_new_item' => 'Ajouter un secteur',
        'new_item_name' => 'Ajouter un nouveau secteur',
        'menu_name' => 'Secteurs',
      );
      register_taxonomy('sectors','books', array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'books' ),
      ));
    }
    add_action('init', 'register_books');
    function register_books()
    {
      $labels = array(
        'name' => 'BOOKS',
        'singular_name' => 'Book',
        'add_new' => 'Ajouter un book',
        'add_new_item' => 'Ajouter un nouveau book',
        'edit_item' => 'Editer un book',
        'new_item' => 'Nouveau book',
        'all_items' => 'Tous les books',
        'view_item' => 'Voir le book',
        'search_items' => 'Rechercher un book',
        'not_found' =>  'Aucun book',
        'not_found_in_trash' => 'Aucun book dans la corbeille',
        'parent_item_colon' => '',
        'menu_name' => 'Books'
    
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'books' ),
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => 5,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments')
      );
      register_post_type('books',$args);
    }
  • The topic ‘404 when same slug for a custom post type and its custom taxonomy’ is closed to new replies.