WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10791 closed enhancement (fixed)

Allow specific post_types to be specified in query

Reported by: prettyboymp Owned by: 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 5 years ago.
multiple-post-types.patch (1.0 KB) - added by prettyboymp 5 years ago.
latest patch with IN statement

Download all attachments as: .zip

Change History (8)

comment:1 azaozz5 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) . "')";
}

prettyboymp5 years ago

latest patch with IN statement

comment:2 prettyboymp5 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.

comment:3 dd325 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.

comment:4 dd325 years ago

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

comment:5 ryan5 years ago

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

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

comment:6 ryan5 years ago

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