Continue reading Auto-redirecting with one search result

Auto-redirecting with one search result

If you want to auto-direct the user directly to the result if there’s just one result for the search, that’s quite easy. Just add the following code to your theme functions.php: add_action(’template_redirect’, ‘one_match_redirect’); function one_match_redirect() { if (is_search()) { global $wp_query; if ($wp_query->post_count == 1) { wp_redirect( get_permalink( $wp_query->posts[’0’]->ID ) ); exit(); } } }add_action(‘template_redirect’,…

Read more Auto-redirecting with one search result 12 Comments on Auto-redirecting with one search result