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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -