Allow querying multiple post types. Props prettyboymp. fixes #10791

git-svn-id: http://svn.automattic.com/wordpress/trunk@12144 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-11-05 16:08:53 +00:00
parent c3041b4f56
commit 795d034b4a
1 changed files with 12 additions and 3 deletions

View File

@ -1486,8 +1486,12 @@ class WP_Query {
}
}
if ( !empty($qv['post_type']) )
$qv['post_type'] = sanitize_user($qv['post_type'], true);
if ( !empty($qv['post_type']) ) {
if(is_array($qv['post_type']))
$qv['post_type'] = array_map('sanitize_user', $qv['post_type'], array(true));
else
$qv['post_type'] = sanitize_user($qv['post_type'], true);
}
if ( !empty($qv['post_status']) )
$qv['post_status'] = preg_replace('|[^a-z0-9_,-]|', '', $qv['post_status']);
@ -2072,7 +2076,10 @@ class WP_Query {
$q['orderby'] = "$wpdb->posts.post_date ".$q['order'];
}
$post_type_cap = $post_type;
if ( is_array($post_type) )
$post_type_cap = 'multiple_post_type';
else
$post_type_cap = $post_type;
$exclude_post_types = '';
foreach ( get_post_types( array('exclude_from_search' => true) ) as $_wp_post_type )
@ -2080,6 +2087,8 @@ class WP_Query {
if ( 'any' == $post_type ) {
$where .= $exclude_post_types;
} elseif ( !empty( $post_type ) && is_array( $post_type ) ) {
$where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')";
} elseif ( ! empty( $post_type ) ) {
$where .= " AND $wpdb->posts.post_type = '$post_type'";
} elseif ( $this->is_attachment ) {