Redirect To Post If Search Results Return One Post
Wordpress has a built in search functionality which allows your visitor to easily search for posts on the blog. It can search for keywords in the post title and in the post content.
When a search is performed WordPress will use the search.php file to display you the results. You can customise this page to display the entire list of posts returned from the WordPress database.
The problem is that if WordPress returns only one post in the search results it will still take you to the search.php file and display a list of posts, well the one post.
Below is a WordPress snippet you can add to your functions.php file to check how many posts are returned by the search, if it returns one post then performs a redirect to the post. Read more...