0

The title basically says it all.

I know I can use the following to get posts from the aside post format:

$args = array(
    'post_type'=> 'post',
    'post_status' => 'publish',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-aside' )
        )
    )
);

$asides = get_posts( $args );
foreach ( $asides as $aside ) {
    setup_postdata( $aside );
    // HTML...
}

What I would like to know is how do I get posts that are not in the aside post format?

4

You just need to set the operator parameter to 'NOT IN' (see Codex on tax queries).

Untested, but for your purposes:

$args = array(
    'post_type'=> 'post',
    'post_status' => 'publish',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-aside' ),
            'operator' => 'NOT IN'
        )
    )
);
  • 2
    Thanks. On a side note: I wish there were a simpler way to query post formats. Something like this: 'post-format' => array('aside'). – MegaHit Feb 8 '12 at 0:07
  • Works perfectly – rhysclay May 3 '17 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.