• i have this code in function.php

    function add_my_CPT( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array('post', 'nav_menu_item', 'stories'));
          return $query;
        }
    }

    it add post types to the archive pages.
    but in archive pages i have sidebar with custom queries
    $args2 = array('posts_per_page' => 3, 'post_type' => 'tips');
    so in archive pages the sidebar queries shows all the posts (stories and tips) instead noly tips.

    how can i disable this?

    • This topic was modified 9 years, 1 month ago by yortem.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter yortem

    (@yortem)

    i added ‘if main query’

    function add_my_CPT( $query ) {
       if($query->is_main_query()    && ( is_category() || is_tag() )) {
        $query->set( 'post_type', array('post', 'nav_menu_item', 'stories'));
          return $query;
        }
    }

    and its now works, but i hope i did it ok.
    the code is good?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    That’s exactly what is_main_query is for!

    Thread Starter yortem

    (@yortem)

    thanks.
    another question
    i deleted the
    $query->query_vars['suppress_filters'] )
    can you explain me like im 5 what it does?

    • This reply was modified 9 years, 1 month ago by yortem.
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘exclude sidebar queries’ is closed to new replies.