Make WordPress Core


Ignore:
Timestamp:
02/16/2013 02:08:46 AM (12 years ago)
Author:
nacin
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.