Make WordPress Core


Ignore:
Timestamp:
04/17/2016 03:16:36 AM (8 years ago)
Author:
boonebgorges
Message:

Query: Allow results to be ordered by post_parent__in.

Props postpostmodern.
Fixes #36515.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r37075 r37225  
    14691469     *              Introduced the `$comment_status` and `$ping_status` parameters.
    14701470     *              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`.
    14711472     * @access public
    14721473     *
     
    15241525     *                                                 'RAND(x)' (where 'x' is an integer seed value),
    15251526     *                                                 '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`.
    15271529     *     @type int          $p                       Post ID.
    15281530     *     @type int          $page                    Show the number of posts that would show up on page X of a
     
    27462748        } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) {
    27472749            $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)";
    27492752        }
    27502753
     
    29642967        } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
    29652968            $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 )";
    29662971        } else {
    29672972            $orderby_array = array();
Note: See TracChangeset for help on using the changeset viewer.