0

I have custom post types that are using sub-categories. I can't figure out how to display the sub-category slug. I am trying to make the sub-category name a class name, but it keeps returning "unrecognized", which isn't right because it is a subcategory. Here's the code:

<?php 
  $categories = wp_get_post_terms($post->ID, 'menu_category', $cat_args);
  $args = array('parent' => $caregory->term_id);
  $sub_cats = get_categories( $args );
?>
<div class="menu-item isotope-box-nested <?php foreach($sub_cats as $sub_cat) echo $sub_cat->slug ?>">

Any ideas what I'm doing wrong her?

2
  • What output are you getting? Also, have you tried simply using post_class()?
    – Cedon
    Mar 16, 2017 at 13:28
  • Nice! Didn't know about the post_class() function. That did it! If you want to post as answer, I'll mark it as an answer. Thanks @belinus!
    – bhood
    Mar 16, 2017 at 13:35

1 Answer 1

0

If you use post_class(), it will echo out your classes using just about everything it has on the post.

If you need to manipulate it, get_post_class() function can be used.

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.