I want to prevent posts from displaying in my archives if the post has a certain tag assigned to it. How can I do this? Thanks.
Milan Petrovic answers:
Open your theme archive.php or category.php template, and before the have_posts() call add this:
$wp_query->set("tag__not_in", array(723, 42));
instead of 723, 42 you can add list of your own tags to exclude. Tags must be stated as numbers using tags ID's (tag or term ID).
If you don't want to meddle with code then use the Simply Exclude plugin. That plugin will exclude posts based on tags from the archives.
The plugin can also exclude posts based on category.
<?php global $wp_query;
Place this in the archive.php and before "the loop" which is before this <?php while (have_posts()) : the_post(); ?>
Here 9 is the id of the tag that i want to exclude.
Check out http://www.siddatwork.com/projects/test/?m=201003
Tag "people" is of ID 9 and gets excluded in the archive view but is visible on the homepage, for the post entitled "ex1"
Sorry, forgot to mention - I don't want a plugin solution, I would prefer it in the code/query.