• I am trying to specify some categories to exclude from a gallery listing different types of post.
    Here is the code I have.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array(
    'category__not_in' => array( 144, 145 ),
    'post_type' => 'gallery',
    'posts_per_page' => -1,
    'ignore_sticky_posts' => 1,
    'orderby' => $gogo_gallery_items_order
    					 )
    			  );
    $postcount = 0;
    if ( have_posts() ) : while ( have_posts() ) : the_post(); $postcount++;?>

    I added this line:
    'category__not_in' => array( 144, 145 ),
    but it doesn’t seem to filter the categories I don’t want.
    Anybody know what would be the correct solution?
    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You could just specify which categories you want instead of excluding.

    That said, I have had inconsistent behavior from category__not_in when the posts are in multiple categories, one of which is the one you’re trying to exclude.

    Thread Starter jma666

    (@jma666)

    Thanks for your reply.
    The theme I am using has its own “Gallery” section in the CMS. Therefore, I am assuming the page, by default, displays the 4 categories belonging to this “Gallery” section. That’s why I am trying to exclude some of these categories.
    So far, no luck tho…
    What did you mean by “inconsistent behavior”?

    It doesn’t work sometimes as I would have expected. I haven’t dug into the actual code and looked line by line, but it’s probably working as intended.

    Hey jma666, I just ran into a similar problem with category__not_in, 'category__not_in' => array( 144, 145 ) seems to get processed as a string instead of an array, for whatever reason.

    Try putting your exclude IDs into a variable and explode that into an Array for ‘category__not_in’. This is how I got it to work in my circumstance.

    Try this example of your code:

    <?php
    $excludes = '144,145';
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( array(
    'category__not_in' => explode(',', $excludes),
    'post_type' => 'gallery',
    'posts_per_page' => -1,
    'ignore_sticky_posts' => 1,
    'orderby' => $gogo_gallery_items_order
    					 )
    			  );
    $postcount = 0;
    if ( have_posts() ) : while ( have_posts() ) : the_post(); $postcount++;?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding post categories from my gallery.’ is closed to new replies.