Title: Exclude post formats from custom loop
Last modified: August 20, 2016

---

# Exclude post formats from custom loop

 *  Resolved [zeaks](https://wordpress.org/support/users/zeaks/)
 * (@zeaks)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/exclude-post-formats-from-custom-loop/)
 * I need to exclude all post formats but the standard from a page template loop
   that displays 4 most recent posts. This is the code I’ve been trying to get working,
   after 3 hours I can make it do just about everything except what I want.
 *     ```
       $args = array(
       	'tax_query' => array(
       		array(
       			'taxonomy' => 'post_format',
       			'field' => 'slug',
       			'terms' => array( 'post-format-aside', 'post-format-image' ),
       			'operator' => 'NOT IN'
       		)
       	)
       );
       $query = new WP_Query( $args );
       ```
   
 * Here is the page template [http://pastebin.com/kf5v7NQf](http://pastebin.com/kf5v7NQf)
   
   Here is the loop [http://pastebin.com/rYk8JdJT](http://pastebin.com/rYk8JdJT)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/exclude-post-formats-from-custom-loop/#post-3170124)
 * your code looks compliant with the code in this post [http://wordpress.mfields.org/2011/post-format-queries/](http://wordpress.mfields.org/2011/post-format-queries/)
 * how does the `WP_Query()` code fit into the code of the page template?
 * btw: the exclusion seems to work in a page template in my local test setup runing
   Twenty Twelve; my example code:
 *     ```
       <?php $formats = new WP_Query( array(
       	'posts_per_page' => 20,
       	'paged' => get_query_var('paged'),
       	'tax_query' => array(
       		array(
       		'taxonomy' => 'post_format',
       		'field'    => 'slug',
       		'terms'    => array( 'post-format-link', 'post-format-aside', 'post-format-gallery' ),
       		'operator' => 'NOT IN',
       		)
       	 )
       ));
       if( $formats->have_posts() ) : while( $formats->have_posts() ) : $formats->the_post();
       echo '<h4>'; the_title(); echo '</h4>';
       endwhile; endif; wp_reset_postdata(); ?>
       ```
   
 * could there be a possible interference from a plugin?
 *  Thread Starter [zeaks](https://wordpress.org/support/users/zeaks/)
 * (@zeaks)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/exclude-post-formats-from-custom-loop/#post-3170137)
 * I don’t have any plugins installed but wp-pagenavi which I’ve removed, and it’s
   a new wp install.
 * I tried this using your example as a test template and it limits the posts but
   won’t filter the formats. The first two posts it displays are an aside and gallery
   format.
 *     ```
       <?php get_header(); ?>
       <?php $formats = new WP_Query( array(
       	'posts_per_page' => 4,
       	'paged' => get_query_var('paged'),
       	'tax_query' => array(
       		array(
       		'taxonomy' => 'post_format',
       		'field'    => 'slug',
       		'terms'    => array( 'post-format-link', 'post-format-aside', 'post-format-gallery' ),
       		'operator' => 'NOT IN',
       		)
       	 )
       ));
       if( $formats->have_posts() ) : while( $formats->have_posts() ) : $formats->the_post();
       	echo '<h4>'; the_title(); echo '</h4>';
       		endwhile; endif; wp_reset_postdata(); ?>
   
       <?php get_sidebar( 'front' ); ?>
       <?php get_footer(); ?>
       ```
   
 *  Thread Starter [zeaks](https://wordpress.org/support/users/zeaks/)
 * (@zeaks)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/exclude-post-formats-from-custom-loop/#post-3170138)
 * Wow nevermind, I think I’ve been staring at this for too long, it does work.
   
   I had been playing around with the posts formats and had them all set as links
   and quotes, everything but what I had excluded.
 * Thanks for the help

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Exclude post formats from custom loop’ is closed to new replies.

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [post format](https://wordpress.org/support/topic-tag/post-format/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 3 replies
 * 2 participants
 * Last reply from: [zeaks](https://wordpress.org/support/users/zeaks/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/exclude-post-formats-from-custom-loop/#post-3170138)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
