A WordPress plugin that provides Network-wide WP_Query for Multisite environment.
This plugin is based on / a improved version of WP_Query_Multisite (a custom version of WP_Query_Multisite).
- Just copy all files into
<ABSPATH>wp-content/plugins/network-wp-query/.
-
Just copy all files into
<ABSPATH>wp-content/mu-plugins/network-wp-query/. -
Move
network-wp-query/loader/50-network-wp-query-loader.phpinto<ABSPATH>wp-content/mu-plugins/.
-
Install via Composer.
composer require devaloka/network-wp-query
-
Install via Composer.
composer require devaloka/network-wp-query
-
Move
network-wp-querydirectory into<ABSPATH>wp-content/mu-plugins/. -
Move
network-wp-query/loader/50-network-wp-query-loader.phpinto<ABSPATH>wp-content/mu-plugins/.
<?php $query = new WP_Query(['network' => true]); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()): $query->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?><?php $query = new WP_Query(['network' => true, 'sites__in' => [1, 2, 3]]); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()): $query->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?><?php $query = new WP_Query(['network' => true, 'sites__not_in' => [1, 2, 3]]); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()): $query->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?><?php $query = new WP_Query(['network' => true, 'posts_per_site' => 1]); ?>
<?php if ($query->have_posts()): ?>
<?php while ($query->have_posts()): $query->the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>| Name | Type | Description |
|---|---|---|
| network | boolint | Whether perform network-wide query. |
| sites__in | int[] | Blog IDs to include in the query. |
| sites__not_in | int[] | Blog IDs to excluded from the query. |
| posts_per_site | int | The number of posts per Site to retrieve. |