How to display all posts not in a post_format

Using WP_Query() I want to display all posts -except- those with the 'image' post_format. I tried this, but it did not work.

    $args = array(
      'relation' = 'NOT',      
      'tax_query' = array(
    array(
        'taxonomy' = 'post_format',
        'field' = 'slug',
        'terms' = array('post-format-' . $post_format),
      )
    ),
        'paged' = get_query_var('paged')
    );
    query_posts( $args );  

Topic post-formats wp-query Wordpress

Category Web


It didn't work because your tax query is missing the operator which should be set to NOT IN. So just add it like so:

'tax_query' => array(
    array(
        'taxonomy' => 'post_format',
        'field'    => 'slug',
        'terms'    => array( 'post-format-' . $post_format ),
        'operator' => 'NOT IN',
    )
),

And please, avoid using query_posts() — use new WP_Query() or get_posts() instead — or hooks such as pre_get_posts for modifying the query parameters.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.