diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
index f8ead26246..bd74746a2b 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 'id=>author_id': |
| 1859 | $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_author"; |
| 1860 | break; |
| 1861 | case 'id=>title': |
| 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 ( 'id=>author_id' == $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 ( 'id=>title' == $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..4390dd10b7 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 = $this->factory->user->create( array( 'role' => 'editor' ) ); |
| 694 | $post_id = $this->factory->post->create( array( 'post_author' => $user_id ) ); |
| 695 | |
| 696 | $q = get_posts( array( 'fields' => 'id=>author_id' ) ); |
| 697 | |
| 698 | $this->assertEquals( $q[ $post_id ], $user_id ); |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * @ticket 43636 |
| 703 | */ |
| 704 | public function test_fields_titles_contains_only_post_ids_and_titles() { |
| 705 | $post_title = 'Test fields titles contains only post ids and titles'; |
| 706 | $post_id = $this->factory->post->create( array( 'post_title' => $post_title ) ); |
| 707 | |
| 708 | $q = get_posts( array( 'fields' => 'id=>title' ) ); |
| 709 | |
| 710 | $this->assertEquals( $q[ $post_id ], $post_title ); |
| 711 | } |
| 712 | |
688 | 713 | } |