Support » Plugin: Display Posts Shortcode » Goes haywire when I force CPT to display on Category pages

  • Resolved LucasHall


    Hi Bill,

    When I add this code (see below) to my functions file, the Display-Posts-Shortcode output seems to go haywire. Meaning: it no longer pulls posts from the right Category, Type, Tag, etc, and instead shows a mix of pages and posts.

    Using this code, I’m able to display my CPT posts on my normal blog category pages – mixed in with my other articles. But the DPS plugin on those page stops filtering the right posts

    Do you see anything in this code that would conflict with your plugin?

    Example Category page:
    Note the “Landlord Tips” widget on the right is DPS (5th down) – and not working correctly. This category page has CPT (tips) and posts sharing the same page.

    P.S. I’m also running Genesis 1.9.2


     Add Custom Post Types to Category Pages - This causes issues on with DISPLAY POSTS SHORTCODES on category pages
     function namespace_add_custom_types( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
         'post', 'tips', 'nav_menu_item'
    	  return $query;
     add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Bill Erickson


    Not only will that conflict with Display Posts Shortcode, it should also conflict with anything else that’s doing a query on the page (your menu, a recent posts widget…).

    You need to include $query->is_main_query() in your if statement. This ensures your code only runs on the main query (the listing of posts on that page).

    For more information, read this article:


    You’re a rockstar! Adding $query->is_main_query() to my if statement worked like a charm. My statement now reads
    if( $query->is_main_query() && is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {

    Thank you again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Goes haywire when I force CPT to display on Category pages’ is closed to new replies.