List posts by tag use variable
-
I would like to grab a list of posts using tags to place within a post. However as this is in a template involving multiple pages I would like to set a variable using a custom field/value for the tag. Here is what I have thus far – the Unknown is where I need to place the variable. Any assistance would be very appreciated.
<?php $term = get_term_by('name','Unknown', 'post_tag'); $args=array( 'tag__in' => array($term->term_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() ) { 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(). ?>
This works if I place the actual tag in the Unknown spot, but I can’t seem to figure out how to utilize a variable in this instance.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘List posts by tag use variable’ is closed to new replies.