admin管理员组

文章数量:1022705

I am trying to intercept the GET request of a post and add a value to it.

function foo($request) {
    $request['vid'] = wp_generate_uuid4();

    return $request;
}
add_filter( 'request', 'foo' );

and hope that it would be available later with

$_REQUEST['vid']

but no access so far any ideas?

I am trying to intercept the GET request of a post and add a value to it.

function foo($request) {
    $request['vid'] = wp_generate_uuid4();

    return $request;
}
add_filter( 'request', 'foo' );

and hope that it would be available later with

$_REQUEST['vid']

but no access so far any ideas?

Share Improve this question asked May 15, 2019 at 12:53 Bat ManBat Man 1031 bronze badge 3
  • WordPress doesn't add vid to the $_REQUEST array. Use get_query_var( 'vid' ) to access the vid value.. – Sally CJ Commented May 15, 2019 at 13:10
  • @SallyCJ 10x man it works. Put in an answer I will accept it – Bat Man Commented May 15, 2019 at 13:20
  • Done, @BatMan.. – Sally CJ Commented May 15, 2019 at 13:40
Add a comment  | 

1 Answer 1

Reset to default 1

WordPress doesn't add the vid to the $_REQUEST array. Instead, it's saved in a class property — see WP::$query_vars which is an array.

And to access the value of items in that array, use get_query_var() like so in your case:

$vid = get_query_var( 'vid' );
echo "vid value is $vid";

I am trying to intercept the GET request of a post and add a value to it.

function foo($request) {
    $request['vid'] = wp_generate_uuid4();

    return $request;
}
add_filter( 'request', 'foo' );

and hope that it would be available later with

$_REQUEST['vid']

but no access so far any ideas?

I am trying to intercept the GET request of a post and add a value to it.

function foo($request) {
    $request['vid'] = wp_generate_uuid4();

    return $request;
}
add_filter( 'request', 'foo' );

and hope that it would be available later with

$_REQUEST['vid']

but no access so far any ideas?

Share Improve this question asked May 15, 2019 at 12:53 Bat ManBat Man 1031 bronze badge 3
  • WordPress doesn't add vid to the $_REQUEST array. Use get_query_var( 'vid' ) to access the vid value.. – Sally CJ Commented May 15, 2019 at 13:10
  • @SallyCJ 10x man it works. Put in an answer I will accept it – Bat Man Commented May 15, 2019 at 13:20
  • Done, @BatMan.. – Sally CJ Commented May 15, 2019 at 13:40
Add a comment  | 

1 Answer 1

Reset to default 1

WordPress doesn't add the vid to the $_REQUEST array. Instead, it's saved in a class property — see WP::$query_vars which is an array.

And to access the value of items in that array, use get_query_var() like so in your case:

$vid = get_query_var( 'vid' );
echo "vid value is $vid";

本文标签: postsIntercept page request and add value to it