Buckk Buckk - 4 months ago 47
PHP Question

How to output taxonomy terms used for WP post?

I'm currently working on a project in wordpress where I have a custom taxonomy created for a list of services applied to that individual post.

<main id="main" role="main" <?php body_class(); ?>>
$services_args = array(
'post_type' => 'sc_project',
$services_query = new WP_Query( $services_args );
if ( $services_query->have_posts() ):

$terms = get_terms( array(
'taxonomy' => 'sc_project_service',
'hide_empty' => false,
) );
<a href="#">Back to Projects</a>
<h2><strong><?php the_title(); ?></strong></h2>
<?php foreach ( $terms as $term ) : ?>
<span><?php echo $term->name; ?></span>
<?php endforeach; ?>
<?php endif; ?>

So my question is, with this block of code I have the ability to output every single taxonomy term used but how do I go about limiting the output to only the ones for that specific post?

Any input would be appreciated.

Thank you!


Use wp_get_post_terms() instead of get_terms():

$terms = wp_get_post_terms( get_the_ID(), 'sc_project_service' );