Support » Fixing WordPress » index.php — How To Hide Posts based on Tags?

  • Resolved mmachine

    (@mmachine)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    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. 🙁

    Matt Hill

    (@gambit37)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘index.php — How To Hide Posts based on Tags?’ is closed to new replies.