WordPress.org

Ready to get started?Download WordPress

Forums

Include AND exclude category at the same time (5 posts)

  1. frmars
    Member
    Posted 3 years ago #

    Hello

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

    • include category 4

    AND

    • exclude category 6

  2. frmars
    Member
    Posted 3 years ago #

    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

  3. frmars
    Member
    Posted 3 years ago #

    Please ?

  4. chinmoy
    Member
    Posted 3 years ago #

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

    Use this.

  5. iftomkins
    Member
    Posted 3 years ago #

    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' ) );?>

Topic Closed

This topic has been closed to new replies.

About this Topic