Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#10791 closed enhancement (fixed)

Allow specific post_types to be specified in query

Reported by: prettyboymp's profile prettyboymp Owned by: ryan's profile ryan
Milestone: 2.9 Priority: low
Severity: normal Version: 2.8.4
Component: Query Keywords: has-patch
Focuses: Cc:

Description

Right now, wp_query only accepts a single post_type or 'any'. It would be nice to be able to specify an array of post_types to use.

Attachments (2)

multiple-post-types.2.patch (1.1 KB) - added by prettyboymp 14 years ago.
multiple-post-types.patch (1.0 KB) - added by prettyboymp 14 years ago.
latest patch with IN statement

Download all attachments as: .zip

Change History (8)

#1 @azaozz
14 years ago

This would probably help when using custom post types too. Wouldn't the SQL be better using

elseif ( !empty( $post_type ) && is_array( $post_type ) ) {
  $where .= " AND $wpdb->posts.post_type IN ('" . join("','", $post_type) . "')";
}

@prettyboymp
14 years ago

latest patch with IN statement

#2 @prettyboymp
14 years ago

Good call with the sql. I've updated this in attachment:ticket:10791:multiple-post-types.patch.

By the way, is there anyway to delete an attachment in Trac. I forgot to check the replace file option when uploading a previous version, hence the multiple-post-types.2.patch.

#3 @dd32
14 years ago

  • Keywords has-patch added

By the way, is there anyway to delete an attachment in Trac.

Yes, But only Trac Admins have that ability.

I forgot to check the replace file option when uploading a previous version

In general, On the WordPress trac its considered best to not replace a existing patch, to allow for those who have downloaded the patch already to see theres a new one there.

#4 @dd32
14 years ago

  • Component changed from General to Query
  • Owner set to ryan

#5 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12144]) Allow querying multiple post types. Props prettyboymp. fixes #10791

#6 @ryan
14 years ago

  • Milestone changed from Unassigned to 2.9
Note: See TracTickets for help on using tickets.