Global search through wordpress multisite network


<?php
$searchfor = get_search_query(); // Get the search query for display in a headline
?>
<h1>Search results for '<?php echo $searchfor; ?>'</h1>
<?php
$query_string=esc_attr($query_string); // Escaping search queries to eliminate potential MySQL-injections
$blogs = get_blog_list( 0,'all' );
$search = new WP_Query($query_string);
if ($search->found_posts>0) {
foreach ( $blogs as $blog ):
switch_to_blog($blog['blog_id']);
foreach ( $search->posts as $post ) {
setup_postdata($post);
$author_data = get_userdata(get_the_author_meta('ID'));
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<p>
<span><?php the_time('Y/m/d') ?></span>
By <?php the_author_posts_link();?> </p>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div id="entry-content"><?php
the_excerpt();
?>
</div>
</div>
<?php
}
endforeach;
else
{
echo "Not Found";
}
restore_current_blog(); // Reset settings to the current blog
?>
Advertisements

One thought on “Global search through wordpress multisite network

  1. This is a great plugin. Quick question, for some reason it’s only searching the page content, and not the page titles as well. Is there any way to fix this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s