Opened 4 years ago
Closed 4 years ago
#10605 closed defect (bug) (fixed)
WordPress Shouldn't Mess with post_type
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9 |
| Component: | Query | Version: | 2.9 |
| Severity: | normal | Keywords: | post_type, wp_query has-patch |
| Cc: |
Description
I have a custom post_type, "restaurant," and I'd like to query for the "restaurant" with name "joes-diner".
query_posts(array( 'post_type' => 'restaurant', 'name' => 'joes-diner', ));
fails because WP sees that I'm querying by name, sets $wp_query->is_single to true, which in turn sets post_type to "post."
If I wanted post_type to be "post" I wouldn't have specified "restaurant", would I?
Patch uses the given post_type when specified.
Attachments (4)
Change History (19)
that code again..
if ( 'any' == $post_type ) {
...
} elseif ( ! empty($post_type) ) {
$where .= " AND $wpdb->posts.post_type = '$post_type'";
} elseif ( is_page....
comment:6
markjaquith — 4 years ago
- Resolution set to fixed
- Status changed from new to closed
11817 - breaks my pages
site not found
sorry i am not familar with trac so i do not know if i should reopen it..
- Resolution fixed deleted
- Status changed from closed to reopened
11817 - breaks my pages
Confirmed. I'm just going to work out whats causing it..
Its defaulting to 'post' which fufils the !empty() check.. See patch
I'm also a bit suspicious of the $post_type = 'any' on line 1963: http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L1963 It'll prevent querying for any objects of type x which are in a taxonomy, ie. i ask for Posts assoc. with Term5 and i'll receive Posts and Pages assoc. with Term5.. (I think)
I've done some basic testing on this.. in that posts/pages/attachments are queried correctly.
comment:10
dd32 — 4 years ago
attachment 10605.diff added
- Not sure what that !empty() change is for.. (Must've been there awhile then)
- But that post -> empty string seems to do the trick
comment:11
dd32 — 4 years ago
- Version set to 2.9
comment:12
azaozz — 4 years ago
comment:13
ryan — 4 years ago
comment:14
ryan — 4 years ago
Fixed?
comment:15
ryan — 4 years ago
- Resolution set to fixed
- Status changed from reopened to closed

I swear i've written that patch before.
Wouldnt it be better off written as:
{{{{
if ( 'any' == $post_type ) {
...
} elseif ( ! empty($post_type) ) {
$where .= " AND $wpdb->posts.post_type = '$post_type'";
} elseif ( is_page....
}}}
But I'm pretty sure it was written like that for a reason.. And i'm 100% certain theres other tickets for this