0

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!

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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