WordPress.org

Forums

How to show all posts EXCEPT the ones with one tag? (7 posts)

  1. Souljacker7
    Member
    Posted 7 years ago #

    Greetings,

    I'm trying to filter NSFW posts from my main page, but this is not working:

    query_posts("tag=-NSFW");

    Can someone help me please?

  2. Souljacker7
    Member
    Posted 7 years ago #

    No one? :(

    I'm desperated about this and couldn't find it anyware.

    I want to do a NSFW filter on my website, based on tags

  3. iridiax
    Member
    Posted 7 years ago #

    Tags are just not as functional for these sort of things as are categories. Try making a NSFW category and using a conditional tag with the category ID (shown here with category ID 44):

    in_category('44');

    http://codex.wordpress.org/Conditional_Tags

    http://codex.wordpress.org/Template_Tags/in_category

    There is no conditional tag for in_tag().

    Another option is to look for a plugin that lets you choose which posts to have on your main page.

  4. Alex Concha
    Member
    Posted 7 years ago #

    Try with query_posts("tag__not_in=XX"); where XX is the tag ID you want to exclude.

  5. Souljacker7
    Member
    Posted 7 years ago #

    iridiax:

    I'm trying to avoid making a NSFW category. I just doesn't make sense.

    As to the plugin, I've actually found one that does it. But it doesn't give me the option to be able to allow NSFW at the home if I set a cookie to do so.

    xknown:
    It doesn't work :(

  6. gmorehoudh
    Member
    Posted 6 years ago #

    xknown: I'm having this same problem with tag__not_in not working properly. I think it may be a bug. See here:

    http://wordpress.org/support/topic/205818?replies=10
    http://trac.wordpress.org/ticket/7798

  7. superann
    Member
    Posted 6 years ago #

    Try inserting this before your loop:

    //array of tags to exclude, by tag number
    $exclude_tags = array(1,2,3);
    global $wp_query;
    $wp_query->set('tag__not_in',$exclude_tags);
    $wp_query->get_posts();

Topic Closed

This topic has been closed to new replies.

About this Topic