Opened 15 years ago
Closed 15 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: |
Description
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:
query_posts(array( '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)
Change History (3)
Note: See
TracTickets for help on using
tickets.
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.