Search code examples
phpwordpressposts

custom query for taxonomy


I am using this query to show certain posts.

query_posts( array(
                    'post_type' => APP_POST_TYPE,
                    'post_status' => 'publish',
                    'posts_per_page' => 4,
                    APP_TAX_STORE => $term->slug,
                    ),                      
                ) );

Now instead of showing all posts from APP_TAX_STORE => $term->slug I would like to exclude them. I tried all solutions found in this form, but nothing worked. Any Ideas?


Solution

  • You can use tax_query.

    query_posts( array(
      'post_type'      => APP_POST_TYPE,
      'post_status'    => 'publish',
      'posts_per_page' => 4,
      'tax_query'      => array(
        array(
          'taxonomy' => APP_TAX_STORE,
          'field'    => 'slug',
          'terms'    => $term->slug,
          'operator' => 'NOT IN',
        ),
      ),
    ) );