Why is custom post query on category page showing all media library images?
-
I have a custom post type called banners which I use to control the rotating banners on my site. It works on every page except any of the category pages. On any of these pages the banner chooses to display ALL images uploaded to the media library rather than just the banner images. How do I stop this?
Heres some info:
The code I use in my functions file to have custom post types display on category pages:
add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_category() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'used', 'finishing', 'banner' ) ); return $query; }
Query code I’m using to display banners:
<?php $loop = new WP_Query( array('post_type' => 'banner') ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <?php the_post_thumbnail('banners'); ?> </div> <?php endwhile; ?> <?php wp_reset_query(); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Why is custom post query on category page showing all media library images?’ is closed to new replies.