繁体   English   中英

在WP_Query中添加Search(S)参数可以调用未定义的函数is_user_logged_in()

[英]Adding Search (S) parameter to WP_Query gives Call to undefined function is_user_logged_in()

我创建了需要搜索帖子的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语句才能获得此信息? 还是我做的不正确? 这是用于显示它的前端(未登录/已登录的用户)

提前谢谢了!

我遇到了同样的问题。

`$ args = array(

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

);

$ get_all_block_posts =新的WP_Query($ args);`

然后我尝试了:

`$ args =数组(

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

);

$ get_all_block_posts = get_posts($ args);`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM