Answer the question
In order to leave comments, you need to log in
Wordpress CNC from GET parameters?
Greetings, comrades.
There is a link of the form - /catalog/platforms/android/oreo/?p_from=100&p_to=1000&country=russia&style=all&type=all
Tell me how to bring it to this form - /catalog/platforms/android/oreo/100/1000/russia/all/ all
I tried to do it through add_rewrite_rule, but the URL does not change, it just follows the link with GET parameters.
add_action('init', 'do_rewrite');
function do_rewrite(){
add_rewrite_rule( '([\w]+)=([\w+,.-]+)', 'index.php?pagename=catalog&p_from=$matches[1]&p_to=$matches[2]&country=$matches[3]&style=$matches[4]&type=$matches[5]', 'top' );
add_filter( 'query_vars', function( $vars ){
$vars[] = 'p_from';
$vars[] = 'p_to';
$vars[] = 'country';
$vars[] = 'style';
$vars[] = 'type';
return $vars;
} );
}
Answer the question
In order to leave comments, you need to log in
The format is like this
on a regular basis you should have
it will look like this
accordingly you will get such pockets
$matches[0] = /catalog/platforms/android/oreo/100/1000/russia/all/all
$matches[1] = android ; регулярка ([^/]+)
$matches[2] = oreo ; регулярка ([^/]+)
$matches[3] = 100 ; регулярка (\d+)
$matches[4] = 1000 ; регулярка (\d+)
$matches[5] = russia ; регулярка ([^/]+)
$matches[6] = all ; регулярка ([^/]+)
$matches[7] = all ; регулярка ([^/]+)
add_rewrite_rule(
'catalog/platforms/([^/]+)/([^/]+)/(\d+)/(\d+)/([^/]+)/([^/]+)/([^/]+)',
'index.php?pagename=catalog&p_from=$matches[3]&p_to=$matches[4]&country=$matches[5]&style=$matches[6]&type=$matches[7]',
'top'
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question