我正在创建一个需要搜索帖子的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=数组(
'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);`