#13020 closed defect (bug) (fixed)
WP_Query - Post type ignored in taxonomy queries.
Reported by: | d910qf | Owned by: | |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | has-patch, taxonomies, query |
Focuses: | Cc: |
Description
Hi,
I posted this to the wp-hackers mailing list - when you specify a taxonomy term and post types using query_posts the post type is getting ignored on line 2034 of query.php ( $post_type = 'any'; ).
Not sure where to start with fixing it or if this intended?
[Edited rest of message]
This code however always ignores the post_type requirement but still
selects all post types linked to the term_name;
global $wp_query; query_posts( array( 'post_type' => 'my_post_type' , "taxonomy_name" => "term_name", 'showposts' => 10 ) );
Attachments (1)
Change History (10)
#4
@
14 years ago
- Milestone changed from Unassigned to 3.0
Made a slight addition to the commit, The below SQL was added for all taxonomy queries, It'll not be included if a query is directly for a specific post_type (thats not an attachment).
LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) .... ((wp_posts.post_status = 'publish') OR (wp_posts.post_status = 'inherit' AND (p2.post_status = 'publish')))
I've left this open for a question: the post_status will ALWAYS be overridden there still, I'm thinking that should be respected as well, If i request drafts in a taxonomy, i'd expect to recieve drafts.. This might be more important for those using custom post status's.
#6
@
14 years ago
With a post_type of 'book' and a custom taxonomy of 'genre', these query arguments work fine for me:
$args=array( 'genre' => 'mystery', 'post_type' => 'book', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args);
and
$args=array( 'genre' => 'mystery', 'post_type' => 'book', 'post_status' => 'draft', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args);
#8
follow-up:
↓ 9
@
14 years ago
I've tried every variation I can think of but all seem to return all post-types
example:
<?php $wpq = array (post_type =>'movies','taxonomy'=>'series','term'=>$term->slug); $query = new WP_Query ($wpq); while ( have_posts()) : the_post(); ?> <?php the_title(); ?> do other stuff <?php endwhile; ?> Unless my function is wrong, I think it still may be broken
#9
in reply to:
↑ 8
@
14 years ago
Replying to anointed:
I've tried every variation I can think of but all seem to return all post-types
example:
...
$wpq = array (post_type =>'movies','taxonomy'=>'series','term'=>$term->slug);
...
}}}
If your taxonomy is 'series' then
$wpq = array (post_type => 'movies', 'series' => $term->slug);
Otto identified what caused the problem. Dougal Campbell suggested the solution.