Changeset 37225
- Timestamp:
- 04/17/2016 03:16:36 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r37075 r37225 1469 1469 * Introduced the `$comment_status` and `$ping_status` parameters. 1470 1470 * Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts. 1471 * @since 4.6.0 Added 'post_name__in' support for `$orderby`. 1471 1472 * @access public 1472 1473 * … … 1524 1525 * 'RAND(x)' (where 'x' is an integer seed value), 1525 1526 * 'comment_count', 'meta_value', 'meta_value_num', 'post__in', 1526 * and the array keys of `$meta_query`. 1527 * 'post_name__in', 'post_parent__in', and the array keys 1528 * of `$meta_query`. 1527 1529 * @type int $p Post ID. 1528 1530 * @type int $page Show the number of posts that would show up on page X of a … … 2746 2748 } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { 2747 2749 $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); 2748 $where .= " AND $wpdb->posts.post_name IN ('" . implode( "' ,'", $q['post_name__in'] ) . "')"; 2750 $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; 2751 $where .= " AND $wpdb->posts.post_name IN ($post_name__in)"; 2749 2752 } 2750 2753 … … 2964 2967 } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { 2965 2968 $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; 2969 } elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) { 2970 $orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )"; 2966 2971 } else { 2967 2972 $orderby_array = array(); -
trunk/tests/phpunit/tests/post/query.php
r37224 r37225 179 179 } 180 180 181 /** 182 * @ticket 36515 183 */ 184 public function test_post_name__in_ordering() { 185 $post_id1 = self::factory()->post->create( array( 'post_name' => 'id-1', 'post_type' => 'page' ) ); 186 $post_id2 = self::factory()->post->create( array( 'post_name' => 'id-2', 'post_type' => 'page' ) ); 187 $post_id3 = self::factory()->post->create( array( 188 'post_name' => 'id-3', 189 'post_type' => 'page', 190 'post_parent' => $post_id2 191 ) ); 192 193 $ordered = array( 'id-2', 'id-3', 'id-1' ); 194 195 $q = new WP_Query( array( 196 'post_type' => 'any', 197 'post_name__in' => $ordered, 198 'orderby' => 'post_name__in' 199 ) ); 200 201 $this->assertSame( $ordered, wp_list_pluck( $q->posts, 'post_name' ) ); 202 } 203 181 204 function test_post_status() { 182 205 $statuses1 = get_post_stati();
Note: See TracChangeset
for help on using the changeset viewer.