So, I have been looking EVERYWHERE. I tried every kind of combination. So far, nothing. I have to query two posts to show on my front page, of post post-type, not in one category but, most importantly, of the standard post-format. I work with wp 3.9.1. This is the syntax I use:
$query = new WP_Query( array(
'post_type' => 'post',
'cat' => '-1',
'posts_per_page' => 2,
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-gallery', 'post-format-video' ),
'operator' => 'NOT IN'
)
) );
It just does not work. I get two results, but the video and gallery formats are not processed out. I tried also the use of tax_query => array (.....)
with no result at all.
In the first case the $query->have_posts
returns all posts of all formats. In the second case it returns no content at all.
2 Answers
It looks like your syntax is a little off for the tax query. Try this:
$query = new WP_Query( array(
'post_type' => 'post',
'cat' => '-1',
'posts_per_page' => 2,
'tax_query' => array( array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-aside', 'post-format-gallery', 'post-format-link', 'post-format-image', 'post-format-quote', 'post-format-status', 'post-format-audio', 'post-format-chat', 'post-format-video'),
'operator' => 'NOT IN'
) )
);
(Aside: If you’re not using some of those post formats, it’s fine to remove them from the ‘terms’ array. But if the goal is to only display the ‘normal’ format, you might want to leave them all there in case of future content changes.)