Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20040 closed defect (bug) (invalid)

Setting query in pre_get_posts and custom post types unassigned to any category

Reported by: novakpeter's profile novakpeter Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:


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)

#1 @scribu
12 years ago

  • Keywords reporter-feedback added

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"?

#2 @helenyhou
12 years ago

See #19985 and #20032. Also, this doesn't seem like a bug to me - you are on a taxonomy term archive page. The term is set in the query, so you are going to only get posts of any given post type with that term, which is exactly what I would expect.

#3 @novakpeter
12 years 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.

#4 @scribu
12 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.