I am trying to get blog post data in a custom plugin but I couldn't. I get NULL value in var_dump line. Is there any chance to get global $post in custom plugin?
<?php
class Plugin {
public function __construct() {
add_filter( 'filter_1', [ $this, 'function_1' ], 1, 2 );
add_filter( 'filter_1', [ $this, 'function_2' ], 2, 2 );
}
public function register() {
return apply_filters( 'filter_1', true, "xyz" );
}
public function function_1( $param1, $param2 ) {
global $post;
var_dump($post);
return $param_1;
}
public function function_2( $param1, $param2 ) {
return $param_1;
}
}
$plugin = new Plugin;
$plugin->register();
I think you are looking for $_POST
variable. This variable will be available globally after request: http://php.net/manual/en/reserved.variables.post.php
Finally I get a solution:
$request = "test";
$post = new \WP_Query( array( 'pagename' => $request ) );