jeudi 26 février 2015

Get parent categories of custom post type


I'm trying to display all the categories that belong to the custom post type that the user is in.


For example this post: http://bit.ly/1ANisxN Is a custom post type that belongs to this page category: http://bit.ly/1FYscKh


As you can see the page category shows it's child categories which is exactly what I want to achieve it the custom post: http://ift.tt/1BzakEJ


This is the things I have tried in the custom post to show the parent categories with no luck:



<?php echo get_category_parents() ?>


By the way, this is how the category page is echoing its subcategories:



<?php
$terms = get_terms( 'btp_work_category' );
foreach ( $terms as $term ) {
?>
<li><a href="#" data-filter=".filter-<?php echo $term->term_id; ?>"><?php echo $term->name; ?></a></li>
<?php
}
?>


Any idea on how to do this?


For example this category structure:


Electronics (Top category)




  • Cameras (sub category)



    • posts




  • TV (sub category)



    • posts




  • Cellphones (sub category)



    • posts




So If I'm on a cameras post I want to display the top category of it and its subcategories (which are relative to cameras since all are under `Electronics')





Aucun commentaire:

Enregistrer un commentaire