Title: Conditional search result statement
Last modified: August 20, 2016

---

# Conditional search result statement

 *  [WPWally](https://wordpress.org/support/users/wordpresswally/)
 * (@wordpresswally)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/conditional-search-result-statement/)
 * Hi,
 * I am creating a custom search.php and would like to know how to return a different
   statement based on the number of search results. I would like a different statement
   for each of three scenarios:
    1. No results are returned
    2. One result is returned
    3. More than one result is returned
 * So in the first example the page will return _No results where returned_. In 
   the second: _Your search for X returned one result_. And in the third: _Your 
   search for X returned Y results_.
 * OK, hope that explains what I am trying to do. So here is the code I have so 
   far:
 *     ```
       <?php
       global $wp_query;
       $total_results = $wp_query->found_posts;
       ?>
       Your search for <span class="style"><?php echo get_search_query(); ?></span> returned <span class="style"><?php echo $total_results; ?></span> results.
       ```
   
 * So I am able to print out the third option, are there some conditionals I can
   use with this or any other code to create the different statements I mentioned
   above?

The topic ‘Conditional search result statement’ is closed to new replies.

## Tags

 * [search results](https://wordpress.org/support/topic-tag/search-results/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [WPWally](https://wordpress.org/support/users/wordpresswally/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/conditional-search-result-statement/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
