From 795d034b4aad6fc6cc9285e609a7e9d865fb0977 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 5 Nov 2009 16:08:53 +0000 Subject: [PATCH] Allow querying multiple post types. Props prettyboymp. fixes #10791 git-svn-id: http://svn.automattic.com/wordpress/trunk@12144 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 668fadec5..9cce173ae 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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 ) {