From 68007e55025b1e83ee7d8abde683da44f7d1b21b Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 10 Jul 2017 10:01:04 -0700 Subject: [PATCH 1/2] Failing test case for 'fields'=>'ids' not returning IDs --- tests/phpunit/wp_query/test-wp-query.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/phpunit/wp_query/test-wp-query.php b/tests/phpunit/wp_query/test-wp-query.php index fbdf48d7..d7aa55ae 100644 --- a/tests/phpunit/wp_query/test-wp-query.php +++ b/tests/phpunit/wp_query/test-wp-query.php @@ -174,4 +174,22 @@ public function test_wp_query_search_filter_post_type() { $this->assertEquals( 'page', $query->get('post_type') ); $this->assertEquals( array( $page_id ), wp_list_pluck( $query->posts, 'ID' ) ); } + + public function test_wp_query_fields_ids() { + $p1 = self::factory()->post->create(); + $p2 = self::factory()->post->create(); + $p3 = self::factory()->post->create(); + + SolrPower_Sync::get_instance()->load_all_posts( 0, 'post', 100, false ); + $query = new WP_Query( array( + 'solr_integrate' => true, + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + 'fields' => 'ids', + 'orderby' => 'ID', + 'order' => 'ASC', + ) ); + $this->assertEquals( array( $p1, $p2, $p3 ), $query->posts ); + } + } From 3cbc297419f07d9220502f74f0001a1fad306bf1 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 10 Jul 2017 10:14:48 -0700 Subject: [PATCH 2/2] Fix use of 'fields'=>'ids', which should return post IDs --- includes/class-solrpower-wp-query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/class-solrpower-wp-query.php b/includes/class-solrpower-wp-query.php index 3417f144..257c70d1 100644 --- a/includes/class-solrpower-wp-query.php +++ b/includes/class-solrpower-wp-query.php @@ -212,6 +212,9 @@ function posts_request( $request, $query ) { ) ); $posts = $this->parse_results( $search ); + if ( 'ID' === $fields ) { + $posts = array_map( 'intval', wp_list_pluck( $posts, 'ID' ) ); + } $this->found_posts[ spl_object_hash( $query ) ] = $posts; $this->reset_vars();