0

I have added tags to my Custom Post Type. Now I want to use them to create a isotope portfolio, I can load all tags with this code:

<?php $args = array( 'post_type' => 'portfolio', 'posts_per_page' => 24;
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="all <?php echo $tag->slug; ?>">
        <?php echo the_post_thumbnail(); ?>
        <p><?php the_title(); ?></p>
    </div>
<?php endwhile; ?>

But now I want to add the all tags that from each portfolio item to the class="". With <div class="<?php $tag->slug; ?>"> I just get the last tag of all the tags that are used.

I know there are already a lot of posts about this problem, but every post I have found does not seem to work for me.

0

Where are you getting these tags from? Typically, to get a list of tags attached to a post, you'd do:

$some_tags =  wp_get_post_tags( $post_id);

and then itterate through as such:

foreach($some_tags as $tag) {
do stuff 
}
  • I'm Getting those from <?php $tags = get_tags(); ?>, I have that above the loop where i'm getting all the tags so you can click on it to filter. – Steven de Jong May 5 '14 at 21:41
  • Okay, can you do a var_dump($tags) and post what outputs? My guess is, you aren't itterating through the tags properly, as I showed above. – Hybrid Web Dev May 5 '14 at 22:43
  • This do i get from my var_dump http://pastebin.com/Y5prpYUF and a screenshot from the wp-admin tags page http://snag.gy/2q2NW.jpg – Steven de Jong May 6 '14 at 8:15
  • you could probably use the wp_get_post_tags along with wp_list_pluck to pull out the specific property and then implode the result for your list of classes. – codearachnid May 6 '14 at 11:12
  • When I use (wp_get_post_tags), I get the following error: Undefined variable: wp_get_post_tags. If I use (get_tags), I get all the tags that are used. But I only need the tags within the loop. – Steven de Jong May 6 '14 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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