Class: WP_Network_Query

Core class used for querying networks.


Properties

Name Type(s) Default Value Summary
request string SQL for database query.
sql_clauses array SQL query clauses.
query_vars array Query vars set by the user.
query_var_defaults array Default values for query vars.
networks array List of networks located by the query.
found_networks integer The amount of found networks for the current query.
max_num_pages integer The number of pages.

Methods

WP_Network_Query:: __construct( string | array $query = '' )

Constructor. Since 4.6.0.

Sets up the network query, based on the query vars passed.

Arguments

Name Type(s) Default Value Description
$query string | array

{ Optional. Array or query string of network query parameters. Default empty.

@type array        $network__in          Array of network IDs to include. Default empty.
@type array        $network__not_in      Array of network IDs to exclude. Default empty.
@type bool         $count                Whether to return a network count (true) or array of network objects.
                                         Default false.
@type string       $fields               Network fields to return. Accepts 'ids' (returns an array of network IDs)
                                         or empty (returns an array of complete network objects). Default empty.
@type int          $number               Maximum number of networks to retrieve. Default empty (no limit).
@type int          $offset               Number of networks to offset the query. Used to build LIMIT clause.
                                         Default 0.
@type bool         $no_found_rows        Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
@type string|array $orderby              Network status or array of statuses. Accepts 'id', 'domain', 'path',
                                         'domain_length', 'path_length' and 'network__in'. Also accepts false,
                                         an empty array, or 'none' to disable `ORDER BY` clause. Default 'id'.
@type string       $order                How to order retrieved networks. Accepts 'ASC', 'DESC'. Default 'ASC'.
@type string       $domain               Limit results to those affiliated with a given domain. Default empty.
@type array        $domain__in           Array of domains to include affiliated networks for. Default empty.
@type array        $domain__not_in       Array of domains to exclude affiliated networks for. Default empty.
@type string       $path                 Limit results to those affiliated with a given path. Default empty.
@type array        $path__in             Array of paths to include affiliated networks for. Default empty.
@type array        $path__not_in         Array of paths to exclude affiliated networks for. Default empty.
@type string       $search               Search term(s) to retrieve matching networks for. Default empty.
@type bool         $update_network_cache Whether to prime the cache for found networks. Default true.

}


WP_Network_Query:: get_network_ids( )

Used internally to get a list of network IDs matching the query vars. Since 4.6.0.

Returns

integer | array

A single count of network IDs if a count query. An array of network IDs if a full query.


WP_Network_Query:: get_networks( )

Gets a list of networks matching the query vars. Since 4.6.0.

Returns

array | integer

List of WP_Network objects, a list of network ids when 'fields' is set to 'ids', or the number of networks when 'count' is passed as a query var.


WP_Network_Query:: get_search_sql( string $string, array $columns )

Used internally to generate an SQL string for searching across multiple columns. Since 4.6.0.

Arguments

Name Type(s) Default Value Description
$string string

Search string.

$columns array

Columns to search.

Returns

string

Search SQL.


WP_Network_Query:: parse_order( string $order )

Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary. Since 4.6.0.

Arguments

Name Type(s) Default Value Description
$order string

The 'order' query variable.

Returns

string

The sanitized 'order' query variable.


WP_Network_Query:: parse_orderby( string $orderby )

Parses and sanitizes 'orderby' keys passed to the network query. Since 4.6.0.

Arguments

Name Type(s) Default Value Description
$orderby string

Alias for the field to order by.

Returns

string | false

Value to used in the ORDER clause. False otherwise.


WP_Network_Query:: parse_query( string | array $query = '' )

Parses arguments passed to the network query with default query parameters. Since 4.6.0.

Arguments

Name Type(s) Default Value Description
$query string | array

WP_Network_Query arguments. See WP_Network_Query::__construct()


WP_Network_Query:: query( string | array $query )

Sets up the WordPress query for retrieving networks. Since 4.6.0.

Arguments

Name Type(s) Default Value Description
$query string | array

Array or URL query string of parameters.

Returns

array | integer

List of WP_Network objects, a list of network ids when 'fields' is set to 'ids', or the number of networks when 'count' is passed as a query var.


WP_Network_Query:: set_found_networks( )

Populates found_networks and max_num_pages properties for the current query if the limit clause was used. Since 4.6.0.


WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.