I would like to use a shortcode in WordPress to output all the categories that a post is tagged to. With the PHP code I created, all categories are now displayed. How can I get it to display only those. Which are used in the post on what the shortcode is included? Thanks for your help!
function get_cat($post_id) {
$terms = get_terms( array(
'taxonomy' => 'test',
'hide_empty' => true,
) );
echo '<br><strong>Test: </strong>';
foreach ($terms as $term){
echo '<a target="_blank" href="/test/'. $term->slug . '/">' . $term->name . '</a>';
echo ' ';
}
}
add_shortcode( 'get_cat', 'get_cat' );