Hi,
to have a path in Advert Category URLs you can add the code below in your theme functions.php file
add_action("adverts_register_taxonomy", function( $args, $type ) {
if( $type != "advert_category" ) {
return $args;
}
if(!isset($args["rewrite"])) {
$args["rewrite"] = array();
}
$args["rewrite"]["hierarchical"] = true;
return $args;
}, 10, 2 );
After adding the code go to wp-admin / Settings / Permalinks panel and click “Save Changes” button to reset WP router.
For Ad details pages having a taxonomy path in the URL is more complicated and will require a bit more programming, please see https://wordpress.stackexchange.com/questions/94817/add-category-base-to-url-in-custom-post-type-taxonomy for more details.
You can also change the Advert permalink structure using a plugin like Custom Post Type Permalinks https://ww.wp.xz.cn/plugins/custom-post-type-permalinks/
categories work great thanks, https://epolonia.pl/ogloszenia/dania/
Maybe can you guide me how to set ad slug, now its https://epolonia.pl/ogloszenie/ogloszenie/
Based on the StackExchange post i linked to you should be able to have an Ad link with path by adding the code below in your theme functions.php file
add_action( "adverts_post_type", function( $args, $type = null ) {
if( $type !== "advert" ) {
return $args;
}
$args["rewrite"] = array( 'slug' => 'ad/%advert_category%' );
return $args;
}, 10, 2 );
add_filter( 'post_type_link', function( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID, 'advert_category' );
if( $terms ){
return str_replace( '%advert_category%' , $terms[0]->slug, $post_link );
}
}
return $post_link;
}, 1, 3 );
Note this would include in the link the last category in the path, so for example if you have an Ad in category /animals/dogs/pit-bulls/, then the link to an Ad would https://example.com/ad/put-bulls/ad-name-here/.
If you would like to have a full path in the URL then you should be able to do that with Custom Post Type Permalinks plugin i linked to in the last message.