I have code:
class some{
public function run(){
add_filter('query_vars', array( $this, 'addPar'));
$this->some_body();
}
public function addPar($vars){
$vars[] = "my_par";
return $vars;
}
public function some_body(){
if(isset( get_query_var('my_par')) {
$value = get_query_var('my_par');
echo $value;
}
echo '<li><a href="'.esc_url(add_query_arg(array('my_par' => '4'))).'">></a></li>';
}
}
And get_query_var()
not work.
SOLUTION
In back-end this function not work probably. I use instead $_GET
.
I have code:
class some{
public function run(){
add_filter('query_vars', array( $this, 'addPar'));
$this->some_body();
}
public function addPar($vars){
$vars[] = "my_par";
return $vars;
}
public function some_body(){
if(isset( get_query_var('my_par')) {
$value = get_query_var('my_par');
echo $value;
}
echo '<li><a href="'.esc_url(add_query_arg(array('my_par' => '4'))).'">></a></li>';
}
}
And get_query_var()
not work.
SOLUTION
In back-end this function not work probably. I use instead $_GET
.
- I change little code but idea is the same - after click link variable is not registered in WP Query in "public query_vars". – Jaron Commented Apr 3, 2019 at 11:41
- Can you see something in debug.log? – middlelady Commented Apr 3, 2019 at 19:05
- i have define WP_DEBUG, WP_DEBUG_LOG and SCRIPT_DEBUG as TRUE but i not have debug.log file in /wp-content. Plugin WP Live Debug display nothing. I testing my plugin in localhost. – Jaron Commented Apr 3, 2019 at 19:17
- Ok, I'd suggest to fix this issue before, it could be really helpful. – middlelady Commented Apr 3, 2019 at 19:23
- Debug display nothing. I testing my plugin in localhost. – Jaron Commented Apr 3, 2019 at 19:24
1 Answer
Reset to default 1some_body
needs to be run as an action on pre_get_posts
.
Here's an example of the entire process of adding new query vars.
Pay extra attention to myplugin_pre_get_posts
:
function myplugin_pre_get_posts( $query ) {
...
$city = get_query_var( 'city' );
...
}
add_action( 'pre_get_posts', 'myplugin_pre_get_posts', 1 );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745307308a4621788.html
评论列表(0条)