WordPress.org

Make WordPress Core

Changeset 23436


Ignore:
Timestamp:
02/16/13 02:08:46 (3 years ago)
Author:
nacin
Message:

WP_Query: post_parent__in and post_parent__not_in. props wonderboymusic. fixes #11056.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp.php

    r23416 r23436  
    2626     * @var array 
    2727     */ 
    28     var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in'); 
     28    var $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in' ); 
    2929 
    3030    /** 
  • trunk/wp-includes/query.php

    r23416 r23436  
    14071407        } 
    14081408 
    1409         $array_keys = array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 
    1410             'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and'); 
     1409        $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 
     1410            'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in' ); 
    14111411 
    14121412        foreach ( $array_keys as $key ) { 
     
    21682168        } 
    21692169 
    2170         if ( is_numeric($q['post_parent']) ) 
     2170        if ( is_numeric( $q['post_parent'] ) ) { 
    21712171            $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); 
     2172        } elseif ( $q['post_parent__in'] ) { 
     2173            $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); 
     2174            $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; 
     2175        } elseif ( $q['post_parent__not_in'] ) { 
     2176            $post_parent__not_in = implode( ',',  array_map( 'absint', $q['post_parent__not_in'] ) ); 
     2177            $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; 
     2178        } 
    21722179 
    21732180        if ( $q['page_id'] ) { 
     
    23402347        } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { 
    23412348            $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; 
     2349        } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) { 
     2350            $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )"; 
    23422351        } else { 
    23432352            // Used to filter values 
Note: See TracChangeset for help on using the changeset viewer.