Thread Starter
Reobed
(@reobed)
Hi,
this is not possible in WPAdverts by default, and as far as i know WordPress does not support such links out-of-box as well.
I did some research and it looks like with some additional custom programming you can create links like that. There is a code snippet which explains how to do that here https://gist.github.com/kasparsd/2924900. You will, of course, need to modify it to use the ‘advert’ post type and advert_location taxonomy.
You can also use a plugin https://pl.ww.wp.xz.cn/plugins/custom-post-type-permalinks/, but it looks like it will not allow you to have a permalink scheme exactly as in your example.
Here is a whole code to convert the permalinks from https://example.com/advert/bike/ to https://example.com/advert/danmark-kobenhavn/bike/
// Add our custom permastructures for custom taxonomy and post
add_action( 'wp_loaded', 'add_advert_permastructure' );
function add_advert_permastructure() {
global $wp_rewrite;
add_permastruct( 'advert', 'advert/%advert_location%/%advert%', false );
}
// Make sure that all links on the site, include the related texonomy terms
add_filter( 'post_type_link', 'custom_advert_permalinks', 10, 2 );
function custom_advert_permalinks( $permalink, $post ) {
if ( $post->post_type !== 'advert' ) {
return $permalink;
}
$terms = get_the_terms( $post->ID, 'advert_location' );
if ( ! $terms ) {
return str_replace( '%advert_location%/', '', $permalink );
}
$post_terms = array();
$taxonomy = "advert_location";
$term = $terms[0];
do {
$post_terms[$term->term_id] = $term->slug;
$term = get_term( $term->parent, $taxonomy );
} while( !$term instanceof WP_Error );
$post_terms = array_reverse( $post_terms );
return str_replace( '%advert_location%', implode( '-', $post_terms ) , $permalink );
}
The code you can add in your theme functions.php file, after adding it go to wp-admin / Settings / Permalinks panel and click the “Save Changes” button to reset WP router and apply new URL schemes.
Thread Starter
Reobed
(@reobed)
Thanks.
we’ll give it a try !