![](/img/trans.png)
[英]Wordpress: Fatal error: Call to undefined function 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.