WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a seach page in which am showing results based on keyword and custom category search. Issue i am facing is that, I need to display the count of results. I had referred the wordpress documentation and found some codes, for eg :

<h2 class="pagetitle">Search Result for <?php 
    /* Search Count */ 
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1); 
    $count = $allsearch->post_count; 
    _e('<span class="search-terms">'); 
    echo $key; 
    _e(' &mdash; '); 
    echo $count . ' '; 

But this displays the total search results and I need results count filtered by found in the specified category

share|improve this question
pay attention that showposts arguments is deprecated as of version 2.1, use posts_per_page instead – Eugene Manuilov Jun 6 '12 at 7:10

Have you tried wp_count_posts ? http://codex.wordpress.org/Function_Reference/wp_count_posts

I think that will work here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.