• Hi, I’ve been using WP for many years, but I still have problems with a very simple feature :

    I want all posts that are in category 7537 but that aren’t in category 4.

    According to the codex and most of the web, I got this :

    $args = array(
    “category__in” => 7537,
    ‘category__not_in’ => 4,
    ‘posts_per_page’ =>10
    );

    $posts_array = query_posts( $args );

    Returning 0 results, but there are some posts realizing these conditions (a lot) in the database. What’s the good way to get it ?

    Thanks a lot

Viewing 1 replies (of 1 total)
  • This code (untested) should be close to what you want:

    $args = array(
    	'post_type' => 'post',
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => array( 7537 )
    		),
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => array( 4 ),
    			'operator' => 'NOT IN'
    		)
    	)
    );
    $query = new WP_Query( $args );
Viewing 1 replies (of 1 total)
  • The topic ‘Query_posts : include AND exclude categories’ is closed to new replies.