please check this wordpress script for me, it is not working. I want to get the first tag of the post and query all other posts who have the same tag. TY!
<? // Start related posts by tag
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if (1 == $count) {
$tag = $tag->slug . ' ';
}
}
}
query_posts('tag='.$tag.'&posts_per_page=-1');
while (have_posts()) : the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<? endwhile;
wp_reset_query(); ?>
Not sure about the rest of the logic of your code but one problem is the fact that you are using the same
$tagvariable to loop through the$posttagsas well as store your first tag value. Instead of doing something so complex, why not just use the first value in your$posttagsarray.Something like this –