I've built a website and our client currently wants to custom post type to align with their old URL structure which used pages instead of a CPT, but because the website now uses WP queries all over the site for sliders to these post types it wasn't feasible to keep this as pages.
Here is some info about my CPT:
- Name: opleidingen
- slug: opleidingen_en_cursussen
- category name: cursus_opleiding_categorie
- terms: opleidingen, reiki-cursussen
The current URL structure is as follows:
/opleidingen_en_cursussen/holistisch-therapeut/
Where holistisch-therapeut is the post itself
The desired URL structure is as follows:
/opleidingen/holistisch-therapeut/
So /cursus_opleidingen_categorie/post
I've searched stackoverflow and google, but Ive only managed to find instances where either of these were fixed, either the post type was removed OR the category was included, but I can't seem to understand the code enough to edit it and fix it so that both of these happen at the same time. I've tried a CPT permalinks plugin but it forces the post type to be present.
I've attached the custom post type file in case this is needed:
<?php
function register_opleiding_post_type() {
// Opleidingen
$labels = array(
'name' => __('Opleidingen & Cursussen', 'saleswizard_admin'),
'singular_name' => __('Opleiding', 'saleswizard_admin'),
'add_new' => __('Nieuwe Opleiding', 'saleswizard_admin'),
'add_new_item' => __('Nieuwe Opleiding', 'saleswizard_admin'),
'edit_item' => __('Opleiding Bewerken', 'saleswizard_admin'),
'new_item' => __('Nieuwe Opleiding', 'saleswizard_admin'),
'view_item' => __('Opleiding bekijken', 'saleswizard_admin'),
'search_items' => __('Opleidingen Zoeken', 'saleswizard_admin'),
'not_found' => __('Geen Opleidingen gevonden', 'saleswizard_admin'),
'not_found_in_trash' => __('Geen Opleidingen gevonden in de prullenbak', 'saleswizard_admin'),
'parent_item_colon' => __('Bovenliggende Opleiding:', 'saleswizard_admin')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'opleidingen_en_cursussen',
'with_front' => false
),
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-learn-more',
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail'),
'has_archive' => true
);
register_post_type('opleidingen', $args);
$labels = array(
'name' => _x('Opleiding Categorieën', 'taxonomy general name', 'saleswizard_admin'),
'singular_name' => _x('Opleiding Categorie', 'taxonomy singular name', 'saleswizard_admin'),
'search_items' => __('Zoek Opleiding Categorieën', 'saleswizard_admin'),
'popular_items' => __('Populaire Opleiding Categorieën', 'saleswizard_admin'),
'all_items' => __('Alle Opleiding Categorieën', 'saleswizard_admin'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Bewerk Opleiding Categorie', 'saleswizard_admin'),
'update_item' => __('Update Opleiding Categorie', 'saleswizard_admin'),
'add_new_item' => __('Nieuwe Opleiding Categorie Toevoegen', 'saleswizard_admin'),
'new_item_name' => __('Nieuwe Opleiding Categorie Naam', 'saleswizard_admin'),
'separate_items_with_commas' => __('Scheid Opleiding Categorieën met komma', 'saleswizard_admin'),
'add_or_remove_items' => __('Opleiding Categorieën Toevoegen of Verwijderen', 'saleswizard_admin'),
'choose_from_most_used' => __('Kies van de meeste gebruikte Opleiding Categorieën', 'saleswizard_admin')
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'cursus_opleiding_categorie',
"with_front" => true,
),
'has_archive' => true
);
register_taxonomy('cursus_opleiding_categorie', 'opleidingen', $args);
}
?>