Query: Allow results to be ordered by `post_parent__in`.

Props postpostmodern.
Fixes #36515.
Built from https://develop.svn.wordpress.org/trunk@37225


git-svn-id: http://core.svn.wordpress.org/trunk@37191 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-04-17 03:17:27 +00:00
parent 0e2978a5cd
commit 54cf1d2c3d
2 changed files with 8 additions and 3 deletions

View File

@ -1468,6 +1468,7 @@ class WP_Query {
* @since 4.5.0 Removed the `$comments_popup` parameter. * @since 4.5.0 Removed the `$comments_popup` parameter.
* Introduced the `$comment_status` and `$ping_status` parameters. * Introduced the `$comment_status` and `$ping_status` parameters.
* Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts. * Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts.
* @since 4.6.0 Added 'post_name__in' support for `$orderby`.
* @access public * @access public
* *
* @param string|array $query { * @param string|array $query {
@ -1523,7 +1524,8 @@ class WP_Query {
* 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', * 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand',
* 'RAND(x)' (where 'x' is an integer seed value), * 'RAND(x)' (where 'x' is an integer seed value),
* 'comment_count', 'meta_value', 'meta_value_num', 'post__in', * 'comment_count', 'meta_value', 'meta_value_num', 'post__in',
* and the array keys of `$meta_query`. * 'post_name__in', 'post_parent__in', and the array keys
* of `$meta_query`.
* @type int $p Post ID. * @type int $p Post ID.
* @type int $page Show the number of posts that would show up on page X of a * @type int $page Show the number of posts that would show up on page X of a
* static front page. * static front page.
@ -2745,7 +2747,8 @@ class WP_Query {
$where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'"; $where .= " AND $wpdb->posts.post_name = '" . $q['attachment'] . "'";
} elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) {
$q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] );
$where .= " AND $wpdb->posts.post_name IN ('" . implode( "' ,'", $q['post_name__in'] ) . "')"; $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'";
$where .= " AND $wpdb->posts.post_name IN ($post_name__in)";
} }
// If an attachment is requested by number, let it supersede any post number. // If an attachment is requested by number, let it supersede any post number.
@ -2963,6 +2966,8 @@ class WP_Query {
$orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )";
} elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
$orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )";
} elseif ( $q['orderby'] == 'post_name__in' && ! empty( $post_name__in ) ) {
$orderby = "FIELD( {$wpdb->posts}.post_name, $post_name__in )";
} else { } else {
$orderby_array = array(); $orderby_array = array();
if ( is_array( $q['orderby'] ) ) { if ( is_array( $q['orderby'] ) ) {

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.6-alpha-37224'; $wp_version = '4.6-alpha-37225';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.