{"id":3043477,"date":"2012-09-14T02:01:48","date_gmt":"2012-09-14T02:01:48","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/conditional-search-result-statement\/"},"modified":"2016-08-20T15:39:38","modified_gmt":"2016-08-20T15:39:38","slug":"conditional-search-result-statement","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/conditional-search-result-statement\/","title":{"rendered":"Conditional search result statement"},"content":{"rendered":"<p>Hi,<\/p>\n<p>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:<\/p>\n<ol>\n<li>No results are returned<\/li>\n<li>One result is returned<\/li>\n<li>More than one result is returned<\/li>\n<\/ol>\n<p>So in the first example the page will return <em>No results where returned<\/em>.  In the second: <em>Your search for X returned one result<\/em>.  And in the third: <em>Your search for X returned Y results<\/em>.<\/p>\n<p>OK, hope that explains what I am trying to do.  So here is the code I have so far:<\/p>\n<pre><code>&lt;?php\nglobal $wp_query;\n$total_results = $wp_query-&gt;found_posts;\n?&gt;\nYour search for &lt;span class=&quot;style&quot;&gt;&lt;?php echo get_search_query(); ?&gt;&lt;\/span&gt; returned &lt;span class=&quot;style&quot;&gt;&lt;?php echo $total_results; ?&gt;&lt;\/span&gt; results.<\/code><\/pre>\n<p>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?<\/p>\n","protected":false},"template":"","class_list":["post-3043477","topic","type-topic","status-closed","hentry","topic-tag-search-results"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/3043477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/3043477\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=3043477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}