Skip to content

Instantly share code, notes, and snippets.

@msaari
Created May 5, 2020 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaari/3d59794052e97fa6f09194f4364f514e to your computer and use it in GitHub Desktop.
Save msaari/3d59794052e97fa6f09194f4364f514e to your computer and use it in GitHub Desktop.
<?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();
}
if ($wp_query->post_count == 0) {
wp_redirect( 'https://officeinmalta.com/' );
exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment