Support » Plugins and Hacks » query_posts excluding cat by slug

  • Resolved Dunkkan

    (@dunkkan)


    Hello guys,

    I’m currently working in a custom loop :

    <?php query_posts ($query_string.'&offset=3') ; ?>
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	      the_post();
    		?>
    		<!-- etc -->

    I need to add something to exclude certain category by its slug.
    I don’t know how to do it.

    Many thanks for any help !

Viewing 5 replies - 1 through 5 (of 5 total)
  • This doesn’t seems to work. I founded here :

    <?php query_posts ($query_string.'offset=3') ; ?>
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	      the_post();
    		?>
    		<?php if ( is_category('MySlugToExclude') ) continue; ?>
    		<!-- rest of the loop here -->

    I tried both : in_category and is_category, but I’m printing still what I try to exclude.

    Something like:

    <?php
    $slug = 'cat-slug-here';
    $category = get_category_by_slug($slug);
    query_posts($query_string . '&cat=' . $category->cat_ID);
    ?>

    Michael, this is actually awesome. I just added a negative sign in '$cat=-'.

    Thank you !

    Does anyone know how to exclude post from certain category even if post are belong to multiple category.

    Example-> Post A belongs to Category B and C
    i used query_post with cat=-B
    And Post A still show (I guess) because it belongs to C.

    Is there any work around??

    Thank you,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘query_posts excluding cat by slug’ is closed to new replies.