Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ericandrewlewis/WP_Query_Multisite

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
26 Commits
 
 
 
 

Repository files navigation

WP_Query_Multisite is a subclass of WP_Query, WordPress' post querying class. The class does everything behind the scenes, so the only change you make to query multisite is the in the class declaration expression.

Example usage:

$query = new WP_Query_Multisite( array( 'post_type' => 'post' ) );

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 key 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.

Example usage:

$args = array(
	'post_type' => 'post',
	'sites' => array(
		'sites__in' => array( 1, 2, 3, 5 )
	)
);

$query = new WP_Query_Multisite( $args );

while( $query->have_posts() ) : $query->the_post();
    echo $blog_id . get_the_title() . "<br>";
endwhile; 

wp_reset_postdata();

Alternative

We do want to suggest that this version / fork uses pre_get_post and may be a better solution for you. This way you can keep using the good 'ol WP_Query without editing any theme files.
https://github.com/miguelpeixe/WP_Query_Multisite

About

If you're using this reconsider your site architecture or use ElasticSearch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.