Skip to content
A subclass of WP_Query to allow for easy querying of multisite posts
Branch: master
Clone or download
Pull request Compare This branch is 12 commits ahead, 18 commits behind ericandrewlewis:master.
Latest commit 7979074 Jun 17, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md fix example Sep 3, 2013
index.php Fixes notice error. Jan 18, 2016

README.md

WordPress Query Multisite

This is a custom version of WP_Query_Multisite, by ericandrewlewis, to support multisite post queries but without changing the class declaration, we will use the good ol' WP_Query. Just by entering the custom query var multisite => 1 on your query args and your query is now global.


Example usage

$query = new WP_Query( array('multisite' => '1' ) );
while($query->have_posts()) : $query->the_post();
    echo $blog_id . get_the_title() . "<BR>";
endwhile; 
wp_reset_postdata();

To modify what sites are queried, create a 'sites' element in the $args in the constructor parameter, with a sub-element of either 'sites__in' or 'sites__not_in', which will be an array similar to 'posts__in' in the WP_Query object.

$args = array(
	'multisite' => 1,
	'sites__in' => array( 1, 2, 3, 5)
);
$query = new WP_Query( $args );
while($query->have_posts()) : $query->the_post();
    echo $blog_id . get_the_title() . "<BR>";
endwhile; 
wp_reset_postdata();

Automatic multisite search example

On your functions.php:

include_once(TEMPLATEPATH . '/path/to/multisite-query.php');

function my_multisite_search($query) {
	if(!is_admin() && $query->is_main_query() && $query->is_search) {
		$query->set('multisite', 1);
	}
}
add_action('pre_get_posts', 'my_multisite_search');
You can’t perform that action at this time.