I have a custom post type called email_block and have a custom taxonomy called block_type. I need to loop through all the email blocks find out what custom taxonomy (block_type) they have. I know how get all the email block custom post types, it’s finding the what block_type they belong to is what I’m struggling with.
This is the code I have so far. I’m using a relationship field from advanced custom fields to filter what email blocks I want to display.
<?php
$posts = get_field('block_selector');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<a href="https://wordpress.stackexchange.com/questions/152510/<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span>Custom field from $post: <?php the_field('author'); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
You mean get_the_terms()?
<?php
$terms = get_the_terms( $post->ID, 'block_type' );
foreach($terms as $term) {
echo $term->name;
}
?>
Or have I simplified this too much?