0

How would I call out additional posts that have a tag by that matches the current post's title? For example if the current posts is titled "opossum" I would like teasers from all posts tagged with "opossum" to show at the bottom of the page.

2 Answers 2

0

First you need to fetch the current category, then grab posts. So, try

<ul>
<?php
global $post;
$category = get_the_category($post->ID);

$args = array( 'numberposts' => -1, 'offset'=> 1, 'category' => $category );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
2
  • I added that to my template now I'm getting 'Catchable fatal error: Object of class stdClass could not be converted to string in /mnt/www/wordpress/wp-includes/query.php on line 1450'
    – Sam
    Jun 22, 2012 at 21:37
  • I have flagged this to be moved this to the StackOverflow for wordpress
    – Ryan B
    Jun 22, 2012 at 21:41
0
$title_tagged_posts_query = new WP_Query( array(
    'tag' => strtolower( get_the_title() )
) );

while ( $title_tagged_posts_query->have_posts() ) : $title_tagged_posts_query->the_post();
    //Output whatever you want here.
endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.