WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] index.php -- How To Hide Posts based on Tags? (4 posts)

  1. mmachine
    Member
    Posted 4 years ago #

    I'm building a template that for the life of me I can't find a working method to build my main page -- index.php -- so that it will not display posts that have been published with a certain tag.

    From a bit of Googling, the code that looks close as what I need to do goes something like this:

    php query_posts(array('tag__not_in' => array('apple','orange')));

    No luck seeing this work, though. All posts are still displayed on main. I'm a bit of a novice to PHP, so I'm sure it has to do with me failing at proper array logic when using tag__not_in().

    Would love some help in getting this issue fixed! Thanks!

  2. mmachine
    Member
    Posted 4 years ago #

    Figured this out by using this code to build my query:

    <?php
    $args=array(
    'showposts'=>10,
    'tag__not_in' => array('4','6'),
    );
    query_posts($args); ?>

    I was too dead-set on basing the query on the NAMES of my tags that I neglected a method based on the IDs.

  3. foxinni
    Member
    Posted 4 years ago #

    Is there an easy way to get the Tag ID from just the tag name?

    As far as i can see it's really NOT that simple. :(

  4. Matt Hill
    Member
    Posted 4 years ago #

    I'm trying to use the method that mmachine posted above -- but I still can't get tag__not_in to work in WP 2.8.5.

    Does anyone know if there is a bug with tag__not_in -- I've tried many ways of using it and I'm not getting the expected results. Whatever tag I specify to ignore, I'm still getting posts returned with that tag.

Topic Closed

This topic has been closed to new replies.

About this Topic