Posts / custom taxonomy and permalinks
-
Hi all! I have a question for a project under development. I’m using posts to display apartments, categories for locations and for the aim I’ve added two extra taxonomies: offers (sale/rent) and residences (project name to filter apartments by residence). This one classifies posts by project name: an apartment belongs to Vanilla Residence, while other two belong to Eagle Residence, and so on.
The residences taxonomy is registered in functions.php (child theme) as follows:
function cptui_register_my_taxes_residences() { /*** Taxonomy: Residences */ $labels = array( "name" => __( "Residences", "mk_framework" ), "singular_name" => __( "Residence", "mk_framework" ), "menu_name" => __( "Residences", "mk_framework" ), "all_items" => __( "All residences", "mk_framework" ), "edit_item" => __( "Modify residence", "mk_framework" ), "view_item" => __( "View reasidence", "mk_framework" ), "update_item" => __( "Update residence", "mk_framework" ), "add_new_item" => __( "Add new residence", "mk_framework" ), "new_item_name" => __( "New residence", "mk_framework" ), "parent_item" => __( "Parent residence", "mk_framework" ), "parent_item_colon" => __( "Parent residence:", "mk_framework" ), "search_items" => __( "Search residence", "mk_framework" ), "popular_items" => __( "Popular residences", "mk_framework" ), "separate_items_with_commas" => __( "Separate residences with commas", "mk_framework" ), "add_or_remove_items" => __( "Add or remove residences", "mk_framework" ), "choose_from_most_used" => __( "Choose among the most used residences", "mk_framework" ), "not_found" => __( "No residence found", "mk_framework" ), "no_terms" => __( "No residence", "mk_framework" ), "items_list_navigation" => __( "Residence navigation list", "mk_framework" ), "items_list" => __( "Residence list", "mk_framework" ), ); $args = array( "label" => __( "Residence", "mk_framework" ), "labels" => $labels, "public" => true, "hierarchical" => false, "label" => "Residence", "show_ui" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "query_var" => true, "rewrite" => array( 'slug' => 'residences', 'with_front' => true, ), "show_admin_column" => false, "show_in_rest" => false, "rest_base" => "residences", "show_in_quick_edit" => false, ); register_taxonomy( "residences", array( "post" ), $args ); } add_action( 'init', 'cptui_register_my_taxes_residences' );
The above code in fact works in the back-end and I can assign a residence taxonomy to each post. Now the hard part: permalinks are configured as domain.com/%postname%/ but I need to insert the taxonomy in my permalinks:
domain.com/%residences%/%postname%/. The result I want is domain.com/vanilla/v03/, where “vanilla” is the taxonomy slug and “v03” is the post slug.I’ve been unable to find a solution for this, without using a plugin. All my trials have led to 404s for pages and no change to post slugs.
Can anyone assist me?
Thank you in advance!
-M
- The topic ‘Posts / custom taxonomy and permalinks’ is closed to new replies.