diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
index f8ead26246..1dd105246f 100644
|
a
|
b
|
class WP_Query { |
| 1855 | 1855 | case 'id=>parent': |
| 1856 | 1856 | $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent"; |
| 1857 | 1857 | break; |
| | 1858 | case 'author_ids': |
| | 1859 | $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_author"; |
| | 1860 | break; |
| | 1861 | case 'titles': |
| | 1862 | $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_title"; |
| | 1863 | break; |
| 1858 | 1864 | default: |
| 1859 | 1865 | $fields = "{$wpdb->posts}.*"; |
| 1860 | 1866 | } |
| … |
… |
class WP_Query { |
| 2907 | 2913 | return $r; |
| 2908 | 2914 | } |
| 2909 | 2915 | |
| | 2916 | if ( 'author_ids' == $q['fields'] ) { |
| | 2917 | if ( null === $this->posts ) { |
| | 2918 | $this->posts = $wpdb->get_results( $this->request ); |
| | 2919 | } |
| | 2920 | |
| | 2921 | $this->post_count = count( $this->posts ); |
| | 2922 | $this->set_found_posts( $q, $limits ); |
| | 2923 | |
| | 2924 | $r = array(); |
| | 2925 | foreach ( $this->posts as $key => $post ) { |
| | 2926 | $this->posts[ $key ]->ID = (int) $post->ID; |
| | 2927 | $this->posts[ $key ]->post_author = (int) $post->post_author; |
| | 2928 | |
| | 2929 | $r[ (int) $post->ID ] = (int) $post->post_author; |
| | 2930 | } |
| | 2931 | |
| | 2932 | return $r; |
| | 2933 | } |
| | 2934 | |
| | 2935 | if ( 'titles' == $q['fields'] ) { |
| | 2936 | if ( null === $this->posts ) { |
| | 2937 | $this->posts = $wpdb->get_results( $this->request ); |
| | 2938 | } |
| | 2939 | |
| | 2940 | $this->post_count = count( $this->posts ); |
| | 2941 | $this->set_found_posts( $q, $limits ); |
| | 2942 | |
| | 2943 | $r = array(); |
| | 2944 | foreach ( $this->posts as $key => $post ) { |
| | 2945 | $this->posts[ $key ]->ID = (int) $post->ID; |
| | 2946 | $this->posts[ $key ]->post_title = sanitize_text_field( $post->post_title ); |
| | 2947 | |
| | 2948 | $r[ (int) $post->ID ] = sanitize_text_field( $post->post_title ); |
| | 2949 | } |
| | 2950 | |
| | 2951 | return $r; |
| | 2952 | } |
| | 2953 | |
| 2910 | 2954 | if ( null === $this->posts ) { |
| 2911 | 2955 | $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" == $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 ); |
| 2912 | 2956 | |
diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php
index 32f3603537..e37df9308c 100644
|
a
|
b
|
class Tests_Query extends WP_UnitTestCase { |
| 685 | 685 | $this->assertSame( 'tax1', get_query_var( 'taxonomy' ) ); |
| 686 | 686 | $this->assertSame( 'term1', get_query_var( 'term' ) ); |
| 687 | 687 | } |
| | 688 | |
| | 689 | /** |
| | 690 | * @ticket 43636 |
| | 691 | */ |
| | 692 | public function test_fields_author_ids_contains_only_post_ids_and_author_ids() { |
| | 693 | $user_id = self::factory()->user->create( array( |
| | 694 | 'role' => 'editor', |
| | 695 | ) ); |
| | 696 | |
| | 697 | $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); |
| | 698 | |
| | 699 | $q = get_posts( array( 'fields' => 'author_ids' ) ); |
| | 700 | |
| | 701 | $this->assertEquals( $q[ $post_id ], $user_id ); |
| | 702 | } |
| | 703 | |
| | 704 | /** |
| | 705 | * @ticket 43636 |
| | 706 | */ |
| | 707 | public function test_fields_titles_contains_only_post_ids_and_titles() { |
| | 708 | $post_title = 'Test fields titles contains only post ids and titles'; |
| | 709 | $post_id = $this->factory->post->create( array( 'post_title' => $post_title ) ); |
| | 710 | |
| | 711 | $q = get_posts( array( 'fields' => 'titles' ) ); |
| | 712 | |
| | 713 | $this->assertEquals( $q[ $post_id ], $post_title ); |
| | 714 | } |
| | 715 | |
| 688 | 716 | } |