php - Wordpress list category in custom post type -


i have query below want list categories assigned current post viewing.

at moment, lists of categories custom post type. possible list individual post? post type called 'resource' , category attached post type called 'resource-category'.

 <?php       $taxonomy = 'resource-category';       $tax_terms = get_terms($taxonomy);       ?>    <?php       foreach ($tax_terms $tax_term) {       echo '' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "view posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a>&nbsp;&nbsp;&nbsp; ';       } ?> 

you can use wp_get_post_terms:

<?php   $taxonomy = 'resource-category'; $tax_terms = wp_get_post_terms($post->id, $taxonomy, array("fields" => "all"));  foreach ($tax_terms $tax_term) {   echo '' . '<a href="' . esc_attr(get_term_link($tax_term->term_id, $taxonomy)) . '" title="' . sprintf( __( "view posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a>&nbsp;&nbsp;&nbsp; '; }  ?> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -