Ticket #11056: post-parent-in.diff

File post-parent-in.diff, 2.9 KB (added by wonderboymusic, 8 months ago)
Line 
1Index: wp-includes/query.php
2===================================================================
3--- wp-includes/query.php       (revision 21824)
4+++ wp-includes/query.php       (working copy)
5@@ -1407,7 +1407,7 @@
6                }
7 
8                $array_keys = array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
9-                       'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and');
10+                       'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in',);
11 
12                foreach ( $array_keys as $key ) {
13                        if ( !isset($array[$key]) )
14@@ -2168,9 +2168,16 @@
15                        $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
16                }
17 
18-               if ( is_numeric($q['post_parent']) )
19+               if ( is_numeric($q['post_parent']) ) {
20                        $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] );
21-
22+               } elseif ( $q['post_parent__in'] ) {
23+                       $post_parent__in = implode(',', array_map( 'absint', $q['post_parent__in'] ));
24+                       $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)";
25+               } elseif ( $q['post_parent__not_in'] ) {
26+                       $post_parent__not_in = implode(',',  array_map( 'absint', $q['post_parent__not_in'] ));
27+                       $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)";
28+               }
29+               
30                if ( $q['page_id'] ) {
31                        if  ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
32                                $q['p'] = $q['page_id'];
33@@ -2333,6 +2340,8 @@
34                        $orderby = '';
35                } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) {
36                        $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )";
37+               } elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
38+                       $orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )";
39                } else {
40                        // Used to filter values
41                        $allowed_keys = array('name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count');
42Index: wp-includes/class-wp.php
43===================================================================
44--- wp-includes/class-wp.php    (revision 21824)
45+++ wp-includes/class-wp.php    (working copy)
46@@ -25,7 +25,7 @@
47         * @since 2.0.0
48         * @var array
49         */
50-       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');
51+       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');
52 
53        /**
54         * Extra query variables set by the user.