• I’ve been able to display the search results using the code snippet below (thanks to codegurl):
    <?php if ($s) { echo 'You searched for '.$s; } ?>
    That works fine if there are more than one results, but if a search only returns a single result it seems the variable $s doesn’t get populated, so the above statement gets skipped. The search will return the single article containing the result, but the value of $s doesn’t seem to get set on the resulting page.
    Any ideas why that is?
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry chad, but is there some background that we can know. It is difficult to figure out what the reason could be without the rest of the code or solution.
    Perhaps the line just above this checks if there is only one search result and suppresses the line you have posted! I hope you see what I mean. ??

    I think I know what you’re asking. The $s variable gets assigned the search parameters if the search results is more than one. If it isn’t more than one it doesn’t get assigned.
    I think this is by design. Think of it as being similar to Google’s “I’m feeling lucky” button. It automatically takes you to the page that has the highest rank in Google’s search engine. This works a bit the same. When you search for something and only comes up with one result it takes you to the post where the search topic is instead of showing just that one search result.

    Thread Starter chad

    (@chad)

    Thanks Mark.
    2far – The code I mentioned, when inserted into the default index.php page, will print the item searched for when using WP’s builtin search function. It looks like anytime a search has exactly one result WP just directs you to that entry (the url will be appended with index.php?p=5, 5 being the entry id containing the text searched for). When there are more than one search result, or if there aren’t any results you get redirected to a list of results (and the url will be appended as follows: index.php?s=test&x=0&y=0, where the item searched for is test)
    Thanks for the responses. If anyone knows of a way to get around this feature let me know!

    Ian Dunn

    (@iandunn)

    echo $_GET[‘s’];

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘search results’ is closed to new replies.