Get posts from another category with same tag as current post?
-
This is a bit complicated to explain so bear with me…
Q: Inside the loop of a category template, how can I spit out a list of other posts from another category which share the same tag as the current post?
Eg. On my ‘Bands’ overview page, I have a list of bands (each one of which is a post in the ‘Bands’ category), and beside each band I want to show the latest 3 releases (a post from the ‘Releases category) and the first image from each post. Each band and release post is tagged with a band name.
$artist is the tag slug but I don’t think it’s working inside the get_posts query….
Thanks for reading 🙂
Inside the loop of a category template:
<?php $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $artist = $tag->slug . ' '; } } ?> <!-- Latest releases --> <div class="span-4 last"> <h3>~ Latest Releases</h3><?php /* just to test that we have the artist slug... */ echo $artist; ?> <ul> <?php $rand_posts = get_posts('numberposts=1&tag=$artist&category=releases'); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> </div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get posts from another category with same tag as current post?’ is closed to new replies.