plugins - add_query_arg not work in admin

I have code:class some{public function run(){add_filter('query_vars', array( $this, 'addPar')); $t

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.

Share Improve this question edited Jul 21, 2019 at 23:27 Jaron asked Apr 2, 2019 at 23:16 JaronJaron 458 bronze badges 9
  • 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
 |  Show 4 more comments

1 Answer 1

Reset to default 1

some_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

相关推荐

  • plugins - add_query_arg not work in admin

    I have code:class some{public function run(){add_filter('query_vars', array( $this, 'addPar')); $t

    6小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信