Answer the question
In order to leave comments, you need to log in
Why is it impossible to get a variable from a request?
Hello. The situation is as follows. I'm on a product category page using the archive-product.php template.
I add to the URL: site.ru/cat/newparam/value/
do:
add_rewrite_endpoint( 'newparam', EP_ALL );
add_filter( 'query_vars', function ( $vars ) {
$vars[] = 'newparam';
return $vars;
} );
add_rewrite_rule(
"^([^/]+)/newparam/([^&]+)/?$", 'index.php?name=$matches[1]&vidsporta=$matches[2]', 'top'
);
//pagination
add_rewrite_rule(
"^([^/]+)/newparam/([^&]+)/page/([0-9]+)?$", 'index.php?name=$matches[1]&vidsporta=$matches[2]&paged=$matches[3]', 'top'
);
add_filter( 'query_vars', function( $vars ){
$vars[] = 'newparam';
return $vars;
} );
Answer the question
In order to leave comments, you need to log in
The problem was in a custom function that completely changed query_vars. Delete the desired array, and create your own.
But another problem arose.
When I add /page/2/ in the corresponding request I see &newvar=val%2Fpage%2F2. where can this miracle come from? so the variable doesn't work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question