diff --git a/src/wp-includes/class-wp-network-query.php b/src/wp-includes/class-wp-network-query.php index 9390657894..cb42cb478a 100644 --- a/src/wp-includes/class-wp-network-query.php +++ b/src/wp-includes/class-wp-network-query.php @@ -108,8 +108,8 @@ class WP_Network_Query { * 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'. + * '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 network ID. * Default current network ID. @@ -132,7 +132,7 @@ class WP_Network_Query { 'number' => '', 'offset' => '', 'no_found_rows' => true, - 'orderby' => '', + 'orderby' => 'id', 'order' => 'ASC', 'domain' => '', 'domain__in' => '', diff --git a/tests/phpunit/tests/multisite/networkQuery.php b/tests/phpunit/tests/multisite/networkQuery.php index 3317b43137..bec849ba28 100644 --- a/tests/phpunit/tests/multisite/networkQuery.php +++ b/tests/phpunit/tests/multisite/networkQuery.php @@ -59,6 +59,27 @@ class Tests_Multisite_Network_Query extends WP_UnitTestCase { $this->assertEquals( 3, count( $found ) ); } + public function test_wp_network_query_by_network__in_with_order() { + $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] ); + + $q = new WP_Network_Query(); + $found = $q->query( array( + 'fields' => 'ids', + 'network__in' => $expected, + 'order' => 'ASC', + ) ); + + $this->assertEquals( $expected, $found ); + + $found = $q->query( array( + 'fields' => 'ids', + 'network__in' => $expected, + 'order' => 'DESC', + ) ); + + $this->assertEquals( array_reverse( $expected ), $found ); + } + public function test_wp_network_query_by_network__in_with_single_id() { $expected = array( self::$network_ids['wordpress.org/'] );