Created
April 5, 2017 13:08
-
-
Save ihorduchenko/4808a287720193f0b7828ad49b92d5bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//destination file: functions.php | |
add_action('template_redirect', 'single_result'); | |
function single_result() { | |
if (is_search()) { | |
global $wp_query; | |
if ($wp_query->post_count == 1) { | |
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment