M
M
MaKS_Ibl42020-04-26 20:01:40
WordPress
MaKS_Ibl4, 2020-04-26 20:01:40

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;
} );

and get_query_var is empty.
Well I thought. and made rewrite_rule.
The situation is the same. I try various variations and the sense is 0. That is, I remove all the rules, which logically the page does not exist. I add it and it opens, but the variable is empty (what could it be? where to dig?

variation with add_rewrite_rule

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

1 answer(s)
M
MaKS_Ibl4, 2020-04-27
@MaKS_Ibl4

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 question

Ask a Question

731 491 924 answers to any question