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

This code produces

Search Results for "hello" - 1 articles "

<h3>Search Results for <?php echo'"'?>
    <?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; 
    echo '"'; 
    _e(' - '); 
    echo $count . ' '; 
    wp_reset_query(); ?>

How can I make it $single and $plural for eg. "1 article" or "2 articles"?

share|improve this question
Found the answer replace if "_e('articles');" with "($count!=1) { _e(‘articles’); } else { _e(‘article’); }" – Josh Mar 29 '12 at 7:51
up vote 5 down vote accepted

Instead of using 'if' loop it's better to use special function:

<?php echo _n( 'article', 'articles', $count, 'my-plugin-domain' ); ?>


share|improve this answer
+1 This is the proper way to do it. Unfortunately I don't think Poedit parses this correctly though. – Stephen Harris Mar 29 '12 at 8:12
@StephenHarris I can remember creating singular and plural translations in Poedit. Don't believe it should be a problem. – Geert Mar 29 '12 at 8:23
Thank you! Why do you have to use "$count, 'my-plugin-domain'" – Josh Mar 29 '12 at 8:36
@Josh The $count parameter is so the function knows which argument to use: singular or plural. The last parameter is the translation domain. – Geert Mar 29 '12 at 13:18

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.