1

I'm looking for help because I tried to look on the web for a solution but I can't to solve my 404 page issue.

I'm bulding a custom WordPress plugin for my photo club. This plugin wants to display portfolio for each members. Picture are classified by :

  • Author (photographer)
  • Color
  • Theme (the category)

I created a custom post type ms_photo_porfolio and the 3 taxonomies :

  • ms_photo_author for the taxonomy Author
  • ms_photo_color for the taxonomy Color
  • ms_photo_cat for the taxonomy Theme

I want to set the slug /photographies/ of the custom post type as a basename for these 3 taxonomy slugs.

These URLs actually work :

  • thewebsite/photographies/
  • thewebsite/themes/
  • thewebsite/couleurs/
  • thewebsite/membres/

I created 4 pages, and created the template files as index pages.

However I want to transform these URLs to :

  • thewebsite/photographies/
  • thewebsite/photographies/themes/
  • thewebsite/photographies/couleurs/
  • thewebsite/photographies/membres/

I set the parent page Photographie for last 3 pages but these pages leads to a 404 page. It's vital to keep a hierarchical structure for a good SEO.

I know there are a lot of subjets about this issue but I'm confused and lost. I don't want to install a plugin in order to fix my problem (security issues).

Here is the code used in order to register my CPT and taxonomies :

     function ms_register_post_type() {
  $gallery_labels = array(
            'name'                  => _x( 'Photographies des membres', 'Post type general name', 'ms-photo-gallery' ),
            'singular_name'         => _x( 'Galerie', 'Post type singular name', 'ms-photo-gallery' ),
            'menu_name'             => _x( 'Galeries', 'Admin Menu text', 'ms-photo-gallery' ),
            'name_admin_bar'        => _x( 'Galeries', 'Add New on Toolbar', 'ms-photo-gallery' ),
        );
        $gallery_args = array(
            'labels'             => $gallery_labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'rewrite'            => array( 'slug' => 'photographies','with_front' => false ),
            'capability_type'    => 'page',
            'has_archive'        => true,
            'hierarchical'       => true,
            'menu_position'      => 5,
            'supports' => array('title', 'thumbnail', 'post-formats' ),
            'menu_icon'          => 'dashicons-images-alt',
        );
        register_post_type( 'ms_photo_portfolio', $gallery_args );

    }
add_action( 'init', 'ms_register_post_type');
/**
* Register Portfolio taxonomies
*
*
*/
function ms_create_taxonomies() {
    //TAXONOMIE PERSONNALISEE -> CATEGORIES
    $category_labels = array(
        'name'              => _x( 'Thèmes', 'taxonomy general name', 'ms-photo-gallery' ),
        'singular_name'     => _x( 'Thème', 'taxonomy singular name', 'ms-photo-gallery' ),
        'search_items'      => __( 'Rechercher des catégories', 'ms-photo-gallery' ),
        'all_items'         => __( 'Toutes les catégories', 'ms-photo-gallery' ),
        'parent_item'       => __( 'Catégorie parente', 'ms-photo-gallery' ),
        'parent_item_colon' => __( 'Catégorie parente : ', 'ms-photo-gallery' ),
        'edit_item'         => __( 'Éditer la catégorie', 'ms-photo-gallery' ),
        'update_item'       => __( 'Mettre à jour la catégorie', 'ms-photo-gallery' ),
        'add_new_item'      => __( 'Ajouter une catégorie', 'ms-photo-gallery' ),
        'new_item_name'     => __( 'Nom de la catégorie', 'ms-photo-gallery' ),
        'menu_name'         => __( 'Thèmes', 'ms-photo-gallery' ),
    );
    $category_args = array(
        'hierarchical'      => true,
        'labels'            => $category_labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'themes','with_front' => false ),
    );
    register_taxonomy('ms_photo_cat', array('ms_photo_portfolio'), $category_args);
    // TAXONOMIE PERSONNALISEE -> PHOTOGRAPHES
    $photographer_labels = array(
        'name'              => _x( 'Photographes', 'taxonomy general name', 'ms-photo-gallery' ),
        'singular_name'     => _x( 'Photographe', 'taxonomy singular name', 'ms-photo-gallery' ),
        'search_items'      => __( 'Rechercher des photographes', 'ms-photo-gallery' ),
        'all_items'         => __( 'Tous les photographes', 'ms-photo-gallery' ),
        'edit_item'         => __( 'Editer le profil', 'ms-photo-gallery' ),
        'update_item'       => __( 'Mettre à jour le profil', 'ms-photo-gallery' ),
        'add_new_item'      => __( 'Ajouter un profil', 'ms-photo-gallery' ),
        'new_item_name'     => __( 'Nom du photographe', 'ms-photo-gallery' ),
        'menu_name'         => __( 'Photographes', 'ms-photo-gallery' ),
    );
    $photographer_args = array(
        'hierarchical'      => true,
        'labels'            => $photographer_labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'membres','with_front' => false ),
    );
    register_taxonomy('ms_photo_author', array('ms_photo_portfolio'), $photographer_args);
     // Color taxonomy (non-hierarchical)
     $labels = array(
        'name'                       => 'Couleurs',
        'singular_name'              => 'Couleur',
        'search_items'               => 'Rechercher des couleurs',
        'popular_items'              => 'Couleurs populaires',
        'all_items'                  => 'Toutes les couleurs',
        'parent_item'                => null,
        'parent_item_colon'          => null,
        'edit_item'                  => 'Editer la couleur',
        'update_item'                => 'Mettre à jour la couleur ',
        'add_new_item'               => 'Ajouter une couleur',
        'new_item_name'              => 'Nom de la couleur',
        'separate_items_with_commas' => 'Séparer les couleurs avec des virgules',
        'add_or_remove_items'        => 'Ajouter ou supprimer des couleurs',
        'choose_from_most_used'      => 'Choisir parmis les couleurs les plus utilisées',
        'not_found'                  => 'Pas de couleur trouvée.',
        'menu_name'                  => 'Couleurs',

    );

    $args = array(
        'hierarchical'          => false,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'couleurs','with_front' => false  ),
    );
    // associer cette taxonomie au portfolio et aux médias.
    register_taxonomy( 'ms_photo_color', array( 'ms_photo_portfolio' ), $args );
}
add_action('init', 'ms_create_taxonomies');


/**
* Rewrite Flush
*
*
*/
function ms_rewrite_flush() {
    // First, we "add" the custom post type via the above written function.
    // Note: "add" is written with quotes, as CPTs don't get added to the DB,
    // They are only referenced in the post_type column with a post entry, 
    // when you add a post of this CPT.
    ms_register_post_type();

    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'ms_rewrite_flush' );

Thanks in advance for help,

Maral.

0

I think if you change the rewrite in your register_taxonomy $args

'rewrite' => array( 'slug' => 'photographies/couleurs','with_front' => false  ),

This will probably clash with rewriting the custom post type so you'll more than likely get a 404 on this url: http://thewebsite/photographies/ but if you don't need that url then this solution will help you get closer to what you want but I'm pretty sure: http://thewebsite/photographies/couleurs/ will always give you a 404 as within a taxonomy you'll need to create terms then you can link to a page with those terms e.g. http://thewebsite/photographies/couleurs/black-and-white.

  • I already tried this option and Indeed it crashes. I want to use the slug photographies in order to show all the picture independently of the author, the color or of the category. I just want to nest the taxonomy slug in the URL...I didn't found a solution that's why I'm posting thank you in advance – Maral Sabbagh Oct 4 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.