Top

MichaelH on "Show Only Tags?"

March 2, 2010 by  

<?php
$current_cat = intval( get_query_var('cat') );
$tag_name='tag1';
$tag = get_term_by('name', $tag_name, 'post_tag');
if ($tag) {
  $tag_id = $tag->term_id;
  $args=array(
    'cat' => $current_cat,
    'tag__in' => array($tag_id),
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
  );
  $my_query = null;
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    echo 'List of Posts in tag ' . $tag_name . ' and category '.$current_cat;
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
      <?php
    endwhile;
  }
  wp_reset_query();  // Restore global post data stomped by the_post().
}
?>
Be Sociable, Share!
Share

Comments

Facebook comments:

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!





*
Bottom