nicosFR
Member
Posted 2 months ago #
Hi !
I'm trying to mage a custom wp_query to return posts with a certain tag from a certain category. Here is my code:
$bios = new WP_Query();
$args = 'cat=6870&tag=tag1,tag2&showposts=2';
$bios->query($args);
?>
<?php if ($bios->have_posts()) : ?>
...
I know I have posts in the category with the right tags... but the result stays empty... any idea why ?
silentgap
Member
Posted 1 month ago #
Have you tried throwing the post id to the get_the_tags function? So, something like this:
<div class="tag_list">tags:
<?php
$tags = get_the_tags($post->ID);
$total_tag_count=0;
foreach($tags as $tag) {$total_tag_count++;}
$tcount = 0;
foreach($tags as $tag)
{
$tag_name = $tag->name;
$tag_slug = $tag->slug;
echo '<a href="/tag/'.$tag_slug.'" title="'.$tag_name.'">'.$tag_name.'</a>';
$tcount++;
if ($tcount < $total_tag_count)
{
echo ", ";
}
}
?>
</div>
You could probably clean up the first foreach so you only have to use one, but this should give you a general idea.
ref. http://wordpress.org/support/topic/252955