mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-11 22:29:48 +01:00
WP_Query: post_parent__in
and post_parent__not_in
. props wonderboymusic. fixes #11056.
git-svn-id: http://core.svn.wordpress.org/trunk@23436 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
480b83441f
commit
34e93a1155
@ -25,7 +25,7 @@ class WP {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
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');
|
||||
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' );
|
||||
|
||||
/**
|
||||
* Extra query variables set by the user.
|
||||
|
@ -1406,8 +1406,8 @@ class WP_Query {
|
||||
$array[$key] = '';
|
||||
}
|
||||
|
||||
$array_keys = array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
|
||||
'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and');
|
||||
$array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in',
|
||||
'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in' );
|
||||
|
||||
foreach ( $array_keys as $key ) {
|
||||
if ( !isset($array[$key]) )
|
||||
@ -2167,8 +2167,15 @@ class WP_Query {
|
||||
$where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)";
|
||||
}
|
||||
|
||||
if ( is_numeric($q['post_parent']) )
|
||||
if ( is_numeric( $q['post_parent'] ) ) {
|
||||
$where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] );
|
||||
} elseif ( $q['post_parent__in'] ) {
|
||||
$post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) );
|
||||
$where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)";
|
||||
} elseif ( $q['post_parent__not_in'] ) {
|
||||
$post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) );
|
||||
$where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)";
|
||||
}
|
||||
|
||||
if ( $q['page_id'] ) {
|
||||
if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts') ) ) {
|
||||
@ -2339,6 +2346,8 @@ class WP_Query {
|
||||
$orderby = '';
|
||||
} elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) {
|
||||
$orderby = "FIELD( {$wpdb->posts}.ID, $post__in )";
|
||||
} elseif ( $q['orderby'] == 'post_parent__in' && ! empty( $post_parent__in ) ) {
|
||||
$orderby = "FIELD( {$wpdb->posts}.post_parent, $post_parent__in )";
|
||||
} else {
|
||||
// Used to filter values
|
||||
$allowed_keys = array('name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count');
|
||||
|
Loading…
Reference in New Issue
Block a user