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> '; } ?>
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> '; } ?>
Comments
Post a Comment