admin管理员组文章数量:1336663
Is it possible to get count of search results in plugin?
I tried to use pre_get_posts
action, but post_count
always returned 0.
I need to know if there are any search results and if not, then do something else. I know I can edit search.php, but is it possible to make this using plugin?
Is it possible to get count of search results in plugin?
I tried to use pre_get_posts
action, but post_count
always returned 0.
I need to know if there are any search results and if not, then do something else. I know I can edit search.php, but is it possible to make this using plugin?
Share Improve this question edited Jun 24, 2020 at 5:50 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked Jun 23, 2020 at 19:20 TrsakTrsak 11 Answer
Reset to default 0Let's what can be done. Try the bellow code. First I'm checking if it's search query. Then trying to get the count from global query.
function search_count(){
if(is_search()){
global $wp_query;
$not_singular = $wp_query->found_posts > 1 ? 'results' : 'result';
echo $wp_query->found_posts . " $not_singular found";
}
}
本文标签: Get search result count in plugin
版权声明:本文标题:Get search result count in plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742323447a2453253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论