将Search(S)参数添加到WP_Query会调用未定义的函数is_user_logged_in()

时间:2014-10-04 23:32:12

标签: php wordpress wordpress-plugin

我正在创建一个需要搜索帖子的AJAX功能。 目前返回所有这样的工作正常......

    $the_query = new WP_Query(
    array (
        'post_type'        => 'post',
        'posts_per_page'   => '10',
        'post_status'      => 'publish',
        'orderby'          => 'title',
        'order'            => 'ASC',
    )
);
foreach($the_query->posts as $post):
  echo $post->post_title;
endforeach;

然而,当我使用s参数添加搜索时,如下所示...

    $the_query = new WP_Query(
    array (
        's'                => 'mysearch',
        'post_type'        => 'post',
        'posts_per_page'   => '10',
        'post_status'      => 'publish',
        'orderby'          => 'title',
        'order'            => 'ASC',
    )
);
foreach($the_query->posts as $post):
  echo $post->post_title;
endforeach;

然后我收到类似

的错误
Fatal error: Call to undefined function is_user_logged_in() in /wordpress/wp-includes/query.php on line 2084

哪个是核心WP文件,我不确定我正确搜索?我是否必须使用like sql语句来获取此信息?或者我没有正确地做到这一点?!这是用于显示前端(未登录/登录用户)

非常感谢提前!

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题。

`$ args = array(

'post_type' => 'block',
'posts_per_page' => -1

);

$ get_all_block_posts = new WP_Query($ args);`

然后我尝试了:

`$ args = array(

'post_type' => 'block',
'posts_per_page' => -1

);

$ get_all_block_posts = get_posts($ args);`