0

I have some issues with my WordPress website theme. At some point in the creation of the .php files used by the themes, something went wrong. Basically, if I use the post title to create the permalinks in the settings of wordpress back-office, all of my static pages seem to redirect towards home.php. I have tried several things : regenerating the permalinks, changing the slugs of the existing pages, creating a new page. Those were having the same results : accessing the static pages would still redirect me towards home.php...

But when I changed the type of permalinks, using for example the simple ones (with the id of the post in the url), things would be fixed. Same if I kept the "post title" permalink format, but added a parent page to my static pages.

I started debugging and realized that the issue seemed to come from the custom taxonomies that I created, for some custom post type. Indeed, if I comment out the function I used to create the 3 custom taxonomies, aswell as the add_action to load said taxonomies, it works just fine. I believe that I might have forgotten something (in the rewrite property maybe ?) but I have some gaps that need to be filled in my skills.

Below are the declaration of my custom post types and taxonomies, if you see something odd, do let me know ...


function wpm_custom_post_type() {

    $labels = array(
        'name'                => _x( 'Etudiants', 'Post Type General Name'),
        'singular_name'       => _x( 'Etudiant', 'Post Type Singular Name'),
        'menu_name'           => __( 'Les étudiants'),
        'all_items'           => __( 'Les étudiants'),
        'view_item'           => __( 'Voir les étudiants'),
        'add_new_item'        => __( 'Ajouter étudiant'),
        'add_new'             => __( 'Ajouter'),
        'edit_item'           => __( 'Modifier étudiant'),
        'update_item'         => __( 'Mettre à jour étudiant'),
        'search_items'        => __( 'Chercher étudiant'),
        'not_found'           => __( 'Pas de résultat'),
        'not_found_in_trash'  => __( 'Pas de résultat'),
    );

    $args = array(
        'label'               => __( 'Etudiants'),
        'description'         => __( "Les étudiants de l'école"),
        'labels'              => $labels,
        'menu_icon'           => 'dashicons-welcome-learn-more',
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'show_in_rest' => true,
        'hierarchical'        => false,
        'public'              => true,
        'has_archive'         => true,
        'rewrite'             => array( 'slug' => 'students'),

    );

    register_post_type( 'student', $args );


    $labels = array(
        'name'                => _x( 'Modules', 'Post Type General Name'),
        'singular_name'       => _x( 'Module', 'Post Type Singular Name'),
        'menu_name'           => __( 'Modules'),
        'all_items'           => __( 'La formation'),
        'view_item'           => __( 'Voir les modules'),
        'add_new_item'        => __( 'Ajouter un module'),
        'add_new'             => __( 'Ajouter'),
        'edit_item'           => __( 'Modifier le module'),
        'update_item'         => __( 'Mettre à jour le module'),
        'search_items'        => __( 'Chercher modules'),
        'not_found'           => __( 'Pas de résultat'),
        'not_found_in_trash'  => __( 'Pas de résultat'),
    );

    $args = array(
        'label'               => __( 'Modules'),
        'description'         => __( "Les modules de formation"),
        'labels'              => $labels,
        'menu_icon'           => 'dashicons-desktop',
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'show_in_rest' => true,
        'hierarchical'        => false,
        'public'              => true,
        'has_archive'         => true,
        'rewrite'             => array( 'slug' => 'modules'),


    );

    register_post_type( 'module', $args );
}





function wpm_add_taxonomies() {

    $labels_domain = array(
        'name'                       => _x( 'Filières', 'taxonomy general name'),
        'singular_name'              => _x( 'Filière', 'taxonomy singular name'),
        'search_items'               => __( 'Rerchercher filières'),
        'popular_items'              => __( 'Filières populaires'),
        'all_items'                  => __( 'Toutes les filières'),
        'edit_item'                  => __( 'Modifier filière'),
        'update_item'                => __( 'Mettre à jour la filière'),
        'add_new_item'               => __( 'Ajouter une filière'),
        'new_item_name'              => __( 'Nom de la filière'),
        'separate_items_with_commas' => __( 'Ajouter une virgule entre chaque filière'),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer une filière'),
        'choose_from_most_used'      => __( 'Choisir parmi les plus utilisées'),
        'not_found'                  => __( 'Aucune filière trouvée'),
        'menu_name'                  => __( 'Filières'),
    );

    $args_domain = array(
        'hierarchical'          => false,
        'labels'                => $labels_domain,
        'show_ui'               => true,
        'show_in_rest'          => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'domains' ),
    );

    register_taxonomy( 'domain', 'student', $args_domain );

    $labels_year = array(
        'name'                       => _x( 'Promotions', 'taxonomy general name'),
        'singular_name'              => _x( 'Promotion', 'taxonomy singular name'),
        'search_items'               => __( 'Rerchercher promotions'),
        'popular_items'              => __( 'Promotions populaires'),
        'all_items'                  => __( 'Toutes les promotions'),
        'edit_item'                  => __( 'Modifier promotion'),
        'update_item'                => __( 'Mettre à jour la promotion'),
        'add_new_item'               => __( 'Ajouter une promotion'),
        'new_item_name'              => __( 'Nom de la promotion'),
        'separate_items_with_commas' => __( 'Ajouter une virgule entre chaque promotion'),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer une promotion'),
        'choose_from_most_used'      => __( 'Choisir parmi les plus utilisées'),
        'not_found'                  => __( 'Aucune promotion trouvée'),
        'menu_name'                  => __( 'Promotions'),
    );

    $args_year = array(
        'hierarchical'          => false,
        'labels'                => $labels_year,
        'show_ui'               => true,
        'show_in_rest'          => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'year' ),
    );

    register_taxonomy( 'year', 'student', $args_year );

    $labels_training = array(
        'name'                       => _x( 'Formations', 'taxonomy general name'),
        'singular_name'              => _x( 'Formation', 'taxonomy singular name'),
        'search_items'               => __( 'Rerchercher formations'),
        'popular_items'              => __( 'Formations populaires'),
        'all_items'                  => __( 'Toutes les formations'),
        'edit_item'                  => __( 'Modifier formation'),
        'update_item'                => __( 'Mettre à jour la formation'),
        'add_new_item'               => __( 'Ajouter une formation'),
        'new_item_name'              => __( 'Nom de la formation'),
        'separate_items_with_commas' => __( 'Ajouter une virgule entre chaque formation'),
        'add_or_remove_items'        => __( 'Ajouter ou supprimer une formation'),
        'choose_from_most_used'      => __( 'Choisir parmi les plus utilisées'),
        'not_found'                  => __( 'Aucune formation trouvée'),
        'menu_name'                  => __( 'Formations'),
    );

    $args_training = array(
        'hierarchical'          => false,
        'labels'                => $labels_training,
        'show_ui'               => true,
        'show_in_rest'          => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'training' ),
    );

    register_taxonomy( 'training', 'module', $args_training );
}
add_action( 'init', 'wpm_add_taxonomies', 0 );
add_action( 'init', 'wpm_custom_post_type', 0 );
0

And here's the answer to the issue : it was the fact that I named one of my custom taxonomy as year, which probably generated some issues in the query for static pages... Should have noticed that sooner, but hey, at least it's fixed !

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.