Get search result count in plugin

Is it possible to get count of search results in plugin?I tried to use pre_get_posts action, but post_count always retu

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 1
Add a comment  | 

1 Answer 1

Reset to default 0

Let'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";
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742323448a4422277.html

相关推荐

  • Get search result count in plugin

    Is it possible to get count of search results in plugin?I tried to use pre_get_posts action, but post_count always retu

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信