[英]Adding Search (S) parameter to WP_Query gives Call to undefined function is_user_logged_in()
Im creating a AJAX feature that needs to search posts. 我创建了需要搜索帖子的AJAX功能。 Currently returning all like this works fine...
目前像这样返回所有作品都很好...
$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;
However when i add search with s
parameter like below... 但是,当我添加带有
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;
I then get an error like 然后我得到一个错误
Fatal error: Call to undefined function is_user_logged_in() in /wordpress/wp-includes/query.php on line 2084
Which is the core WP files, im not sure im doing search correctly? 核心WP文件是哪一个,我不确定即时搜索是否正确? Will i have to use a
like
sql statement to get this? 我是否必须使用
like
sql语句才能获得此信息? Or am i not doing it correctly?! 还是我做的不正确? This is for displaying it front end (non logged in / logged in users)
这是用于显示它的前端(未登录/已登录的用户)
Many thanks in advance! 提前谢谢了!
I got the same problem. 我遇到了同样的问题。
`$args = array( `$ args = array(
'post_type' => 'block',
'posts_per_page' => -1
); );
$get_all_block_posts = new WP_Query($args);` $ get_all_block_posts =新的WP_Query($ args);`
Then I tried: 然后我尝试了:
` $args = array( `$ args =数组(
'post_type' => 'block',
'posts_per_page' => -1
); );
$get_all_block_posts = get_posts($args);` $ get_all_block_posts = get_posts($ args);`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.