1 | <?php |
---|
2 | /** |
---|
3 | * Provides post_parent__in and __not_in support. |
---|
4 | * |
---|
5 | * Will noop when implemented in core, assuming the query vars |
---|
6 | * are added to WP::$private_query_vars. |
---|
7 | */ |
---|
8 | function nacin_post_parent__in( $where, $object ) { |
---|
9 | global $wpdb, $wp; |
---|
10 | if ( in_array( 'post_parent__in', $wp->private_query_vars ) ) |
---|
11 | return $where; |
---|
12 | |
---|
13 | if ( is_numeric( $object->query_vars['post_parent'] ) ) |
---|
14 | return $where; |
---|
15 | if ( ! empty( $object->query_vars['post_parent__in'] ) ) { |
---|
16 | $post_parent__in = implode(',', array_map( 'absint', $object->query_vars['post_parent__in'][0] ) ); |
---|
17 | $where .= " AND $wpdb->posts.post_parent IN ($post_parent__in)"; |
---|
18 | } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) { |
---|
19 | $post_parent__not_in = implode(',', array_map( 'absint', $object->query_vars['post_parent__not_in'][0] ) ); |
---|
20 | $where .= " AND $wpdb->posts.post_parent NOT IN ($post_parent__not_in)"; |
---|
21 | } |
---|
22 | return $where; |
---|
23 | } |
---|
24 | add_filter( 'posts_where', 'nacin_post_parent__in', 10, 2 ); |
---|