devaloka/network-wp-query

A WordPress plugin that provides Network-wide WP Query for Multisite environment

Installs: 1 254

Dependents: 0

Suggesters: 0

Security: 0

Stars: 16

Watchers: 4

Forks: 2

Open Issues: 6

Type:wordpress-plugin

v0.2.0 2017-04-09 07:33 UTC

This package is auto-updated.

Last update: 2024-10-21 07:04:51 UTC


README

Latest Stable Version Latest Unstable Version License Build Status

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

Installation

Manual Installation

  1. Just copy all files into <ABSPATH>wp-content/plugins/network-wp-query/.

Manual Installation (as a Must-Use plugin)

  1. Just copy all files into <ABSPATH>wp-content/mu-plugins/network-wp-query/.

  2. Move network-wp-query/loader/50-network-wp-query-loader.php into <ABSPATH>wp-content/mu-plugins/.

Installation via Composer

  1. Install via Composer.

    composer require devaloka/network-wp-query

Installation via Composer (as a Must-Use plugin)

  1. Install via Composer.

    composer require devaloka/network-wp-query
  2. Move network-wp-query directory into <ABSPATH>wp-content/mu-plugins/.

  3. Move network-wp-query/loader/50-network-wp-query-loader.php into <ABSPATH>wp-content/mu-plugins/.

Example Usage

Standard Loop

<?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; ?>

Query to several specific Sites

<?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; ?>

Query excluding several specific Sites

<?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; ?>

Limit the number of posts per Site

<?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; ?>

Parameters

References