WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query_posts excluding cat by slug (6 posts)

  1. Dunkkan
    Member
    Posted 5 years ago #

    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 !

  2. Dunkkan
    Member
    Posted 5 years ago #

    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.

  3. MichaelH
    Member
    Posted 5 years ago #

    Something like:

    <?php
    $slug = 'cat-slug-here';
    $category = get_category_by_slug($slug);
    query_posts($query_string . '&cat=' . $category->cat_ID);
    ?>
  4. Dunkkan
    Member
    Posted 5 years ago #

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

    Thank you !

  5. winmonaye
    Member
    Posted 4 years ago #

    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,

  6. Jeriko
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic