weixin_33736832 2015-02-10 23:40 采纳率: 0%
浏览 25

全局$ wp_query; 返回空

Firstly this question is different to this one as I'm talking about accessing $Wp_Query from outside of a loop.

What I'm trying to do

I'm currently just attempting to make an ajax request from a script to a php file called database.php which looks like so.

if (isset($_GET["increase"])) {
    global $wp_query;

    echo var_dump($wp_query);

}

As seen I'm just trying to get anything from the $wp_query this is the output from log.

 XHR finished loading: GET "http://localhost/WCBD/wp-content/themes/Test%20Computing/database.php?increase=1".jquery.js?ver=1.11.1:4 m.ajaxTransport.sendjquery.js?ver=1.11.1:4 m.extend.ajaxjquery.js?ver=1.11.1:4 m.each.m.(anonymous function)myscripts.js?ver=1.2:15 foo.vote_up(index):313 onclick
myscripts.js?ver=1.2:11 
NULL

So it seems that it loaded correctly.

I feel like I'm missing an obvious step or something at being able to access the $wp_query.

Thank you.

  • 写回答

1条回答 默认 最新

  • weixin_33686714 2015-06-24 10:46
    关注

    You'd better to make any function within "action". $wp_query will be initiated already, if you make:

    add_action('init','your_func');function my_func(){
        global $wp_query;
        var_dump($wp_query);
        // or  var_dump($GLOBALS['wp_query']);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊