#20040 closed defect (bug) (invalid)
Setting query in pre_get_posts and custom post types unassigned to any category
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | Cc: |
Description
In functions.php:
function my_query_post_type($query) {
global $wp_query;
if ( is_category() && false == $query->query_vars['suppress_filters'] ){
$query->set( 'post_type', array( 'post', 'my_post_type' ) );
}
return $query;
}
add_filter('pre_get_posts', 'my_query_post_type');
If posts within "my_post_type" custom post type are assigned to a category within custom taxonomy, this code works. If they are not assigned to any category, this code doesn't work for them - but probably should.
Change History (4)
Note: See
TracTickets for help on using
tickets.
Since you're using is_category(), this code is depedant on the global $wp_query instance. Are you sure you didn't mean to use
$query->is_category()?Also, what exactly do you mean by "this code doesn't work for them"?