Answer the question
In order to leave comments, you need to log in
How to set URL rewriting rules?
Somehow it so happened that I'm not strong in regular expressions, as well as in creating CNC (human-readable URLs for WordPress) :-)
Actually the problem:
In WordPress, in the theme we use, there is a custom post type tovar. By default, this post type has a URL structure:
https://oursite.ru/catalog/%tovar_category%/%tovar_name%
%tovar_category%
- product category slug - product %tovar_name%
slug It is https://oursite.ru/%city%/%tovar_name%
%city%
- city name (can change dynamically, can be obtained through the corresponding function) %tovar_name%
- product slug 'slug' => '%city%'
%city%
with the following code:function show_city_permalinks( $post_link, $post ) {
if ( is_object( $post ) && $post->post_type == 'tovar' ) {
return str_replace( '%city%', strtolower( IC_Geo::sc_current_city_lat() ), $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'show_city_permalinks', 1, 2 );
'slug' => 'city/%city%'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question