[wp-hackers] Custom template based on tag associated with post

mailapera mailapera at gmail.com
Thu Apr 9 16:54:51 GMT 2009

I have a query that is not working properly. What I am trying to
accomplish is basically the following: get the post to show an element
if it is associated with a tag, display another if associated with
another tag.

I am currently using this query

$tags = 'mytag';
$myquery = new WP_Query("tag=$tags");?>
<?php if($myquery->have_posts()) : ?>

				my element to show

<?php endif; ?>

And it works only half way, meaning that if I have never associated
the tag with that post the element is not shown, if I ad the tag then
it is shown correctly, but if I remove the tag it keeps on showing the

Could this depend on what? I have checked and the tag list does not
consider the post as still having the tag, so I guess the DB is clear
also. I went checking but I could not tell in any way if the DB still
associates that tag with that post.

Any help is greatly appreciated.

More information about the wp-hackers mailing list