Support » Fixing WordPress » Hide posts with a specific TAG from results

  • Hello,
    I want to hide from results some posts that have a specific tag.
    This, before the “if (have_posts())…”, works to exclude categorys:
    global $query_string; query_posts($query_string.'&cat=-3,-5');
    But I can’t find how to do the same with tags.

    Does anybody know how to do it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,
    You can use the code for tags:-
    $query = new WP_Query( array( 'tag__not_in' => array( 37, 47 ) ) );

    mdshak, thanks for your answer.
    Where should I use that code? Because I put it just before the “if(have_posts())…” in my index.php but it didn’t work.

    Just use this code:-

    I replaced “if(have_posts())” for “if($query->have_posts())” but it didn’t work. Should I use “$query->” in the “while” too?
    I have this:
    <?if (have_posts()) : while (have_posts()) : the_post(); ?>
    I can exclude categories just adding “global $query_string;…”

    <?global $query_string; query_posts($query_string.'&cat=-3,-5');
    if (have_posts()) : while (have_posts()) : the_post();  ?>

    So, how should my code be if I would like to exclude tags instead categories?


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide posts with a specific TAG from results’ is closed to new replies.