diff --git a/includes/class-solrpower-wp-query.php b/includes/class-solrpower-wp-query.php index 147e07ce..779206cf 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(); 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 ); + } + }