Support » Fixing WordPress » Include AND exclude category at the same time

  • Hello

    In my loop, how do I, at the same time :

    • include category 4

    AND

    • exclude category 6

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’ve tried this :

    <?php
    $args = array(
    'cat'=> 4,
    'category__not_in' => 6,
    'paged'=>$paged
    );
    query_posts($args);?>

    and this

    <?php
    
    	$args = array(
    		'category__in' => 4,
    		'category__not_in' => 6,
     		'paged'=>$paged
    	);
    	query_posts($args);?>

    I have no errors, but the category is not excluded

    Please ?

    <?php
    
    	$args = array(
    		'cat' => array(4,-6),
     		'paged'=>$paged
    	);
    	query_posts($args);?>

    Use this.

    I had this same problem, and for some reason (might be a 3.1 bug according to some posts), this is the only thing that worked for me. I am excluding category 28, and including category ‘brands’.

    The main issue, it seems, is that the posts were in multiple categories, not just the one i want to exclude. If the post is JUST in the one I wanted to exclude, then all the excluding plugins, and basic fixes seem to work. But in my situation, this is the query_posts that worked for me! Finally!

    <?php query_posts( array( 'category__not_in' => array(28), 'category_name' => 'brands', 'posts_per_page' => '12', 'paged' => $paged, 'orderby' => 'title', 'order' => 'ASC' ) );?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Include AND exclude category at the same time’ is closed to new replies.