Opened 16 years ago
Closed 15 years ago
#10605 closed defect (bug) (fixed)
WordPress Shouldn't Mess with post_type
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.9 | Priority: | normal |
Severity: | normal | Version: | 2.9 |
Component: | Query | Keywords: | post_type, wp_query has-patch |
Focuses: | 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)
#3
@
16 years ago
that code again..
if ( 'any' == $post_type ) { ... } elseif ( ! empty($post_type) ) { $where .= " AND $wpdb->posts.post_type = '$post_type'"; } elseif ( is_page....
#7
@
16 years ago
11817 - breaks my pages
site not found
sorry i am not familar with trac so i do not know if i should reopen it..
#8
@
16 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
11817 - breaks my pages
Confirmed. I'm just going to work out whats causing it..
#9
@
16 years ago
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.
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