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";
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742323448a4422277.html
评论列表(0条)