Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#8872 closed defect (bug) (fixed)

post_type ignored when it shouldn't be

Reported by: filosofo Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: General Keywords: post_type query
Focuses: Cc:


Sometimes you might want to retrieve a post-like object when you're agnostic about what type of post it is (for example, you don't know whether it's a post, page, or attachment).

This should work:

'post_type' => 'any',
'p' =>  123,

However, it doesn't because WP sees that the "p" is set, sets is_single to true, and then the logic for the post_type part of the where clause means that post_type gets set to 'post'.

Instead, the where clause logic should give the "any" post_type priority, as it must be explicitly set (and therefore can be assumed to be the desired result).

Patch give the "any" post_type priority.

Attachments (1)

post_type_ignored.diff (759 bytes) - added by filosofo 5 years ago.

Download all attachments as: .zip

Change History (3)

filosofo5 years ago

comment:1 Denis-de-Bernardy5 years ago

In the meanwhile, you can add a temporary filter to the query clause for the rare cases where this is needed. Use str_replace to strip out the AND post_type = post.

comment:2 ryan5 years ago

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

(In [10503]) Obey post_type. Props filosofo. fixes #8872

Note: See TracTickets for help on using tickets.