Problem altering this code to get any tag, not just first one
-
This code for getting related posts with the same first tag is brilliant, but now I’m trying to get it to work with any tag, not just the first one. This matches the first tag:
<?php $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?><?php the_title(); ?> <?php endwhile; } wp_reset_query(); } ?>
I’ve tried replacing the first bit with variations on this, but keep getting server errors:
$tags = wp_get_post_tags($post->ID); $taglist = ''; if ($tags) { foreach ($tags as $tag) { $taglist .= $tag->term_id . ','; $args=array( 'tag__in' => array($taglist),
ANy ideas on how to alter the first code example to match any tags in common? Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Problem altering this code to get any tag, not just first one’ is closed to new replies.