I have a custom post type called “project” and a list of 8 CPT categories. On the homepage of my site, I want to call the latest post and echo the project name, excerpt, and category. I have the name and excerpt working, but I cannot figure out how to pull in the custom taxonomy.
I know I can use wp_get_post_terms() to get taxonomy terms assigned to a specific post, but this returns an array of term objects. I don't know how to loop through the return and echo out $term->name each time.
<?php
$args = array(
'meta_key' => 'featured',
'meta_value' => '1',
'post_type' => 'project'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?>
<div class="cpt-feature" style="background: url('<?php echo $backgroundImg[0]; ?>') center center no-repeat; background-size: cover;">
<?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
<?php
echo "<div class='cpt-overlay'>";
echo "<div class='project-information'>";
// NEED TO INSERT CPT CATEGORY HERE
echo "<h3>";
the_title();
echo "</h3>";
echo "<p>";
echo get_field('intro_blurb');
echo "<p><a href='" . get_permalink() . "'>View Project</a></p>";
echo "</div>";
echo "</div>";
echo "</a>";
}
wp_reset_postdata(); } else { }?>