<?php
/**
 * Provides post_parent__in and __not_in support.
 *
 * Will noop when implemented in core, assuming the query vars
 * are added to WP::$private_query_vars.
 */
function nacin_post_parent__in( $where, $object ) {
	global $wpdb, $wp;
	if ( in_array( 'post_parent__in', $wp->private_query_vars ) )
		return $where;

	if ( is_numeric( $object->query_vars['post_parent'] ) )
		return $where;
	if ( ! empty( $object->query_vars['post_parent__in'] ) ) {
		$post_parent__in = implode(',', array_map( 'absint', $object->query_vars['post_parent__in'][0] ) );
		$where .= " AND $wpdb->posts.post_parent IN ($post_parent__in)";
	} elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) {
		$post_parent__not_in = implode(',', array_map( 'absint', $object->query_vars['post_parent__not_in'][0] ) );
		$where .= " AND $wpdb->posts.post_parent NOT IN ($post_parent__not_in)";
	}
	return $where;
}
add_filter( 'posts_where', 'nacin_post_parent__in', 10, 2 );