Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jun 22 '12 at 22:53

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

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>
share|improve this answer
    
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 '12 at 21:37
    
I have flagged this to be moved this to the StackOverflow for wordpress –  Ryan B Jun 22 '12 at 21:41
add comment
$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;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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