Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active March 2, 2021 13:25
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 jchristopher/e9278ad6073e41c884ff52c45dd17c66 to your computer and use it in GitHub Desktop.
Save jchristopher/e9278ad6073e41c884ff52c45dd17c66 to your computer and use it in GitHub Desktop.
<?php
global $post;
$current_blog_id = get_current_blog_id();
get_header();
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// Search Results may be formatted as SearchWP results
// because we're searching cross-site on the main site.
if ( 1 === $current_blog_id ) {
if ( $current_blog_id !== $post->site ) {
switch_to_blog( $post->site );
$post = get_post( $post->id );
get_template_part( 'search-result' );
restore_current_blog();
} else {
$post = get_post( $post->id );
get_template_part( 'search-result' );
}
} else {
get_template_part( 'search-result' );
}
}
} else {
get_template_part( 'template-parts/content/content-none' );
}
get_footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment