#20040 closed defect (bug) (invalid)
Setting query in pre_get_posts and custom post types unassigned to any category
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Post Types | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | mike@… |
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)
comment:3
novakpeter — 16 months ago
- Resolution set to invalid
- Severity changed from major to normal
- Status changed from new to closed
OK, helenyhou is probably right, posts are within that (actually) pre-set term, I see.
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"?