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.

Ok, so I have tried about 5 different WP functions now and no luck. Basically here is what I want to do. I have a custom post type called "work", I have a taxonomy within this custom post type called "type" with 2 types available.. "Case Study" & "Portfolio". Depending on which option is checked off I would like that to print in the class of my container for that item and also be converted to lower case with spaces replaced by underscores.

<aside class="work_item <?php has_term('Portfolio', 'type'); ?>" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?>">

That is what I have now but no luck.. I have tried:

has_term get_the_terms get_term

and no luck... been looking at this so long now feel like I am missing something dumb

Desired output:

<aside class="work_item case_study" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?>">

&

<aside class="work_item portfolio" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?>">

Thanks!

share|improve this question
add comment

1 Answer

Ah, solved it!

<aside class="work_item <?php $posttags = get_the_terms($post->ID, 'type'); if ($posttags) { foreach($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?>" data-type="<?php $posttags = get_the_tags(); if ($posttags) { foreach ($posttags as $tag) { echo str_replace('-','_',$tag->slug . ' '); } } ?>">

had to use the get_the_terms() function

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.