Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created April 12, 2022 16:39
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 searchwpgists/505845bd806359af08688b132c6af8ba to your computer and use it in GitHub Desktop.
Save searchwpgists/505845bd806359af08688b132c6af8ba to your computer and use it in GitHub Desktop.
<?php
// @link https://searchwp.com/documentation/multisite/
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