• WPWally

    (@wordpresswally)


    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.