I am currently building a Wordpress site and I am encountering some difficulty with the following..
I am trying to dynamically add a class to a HTML element by displaying the custom taxonomy name of the current post type, to use as the class name. This is all being done within a Foreach loop.
My code is as follows
<?php
$args = array( 'posts_per_page' => -1, 'post_type' => 'staff', 'orderby' => 'menu_order',
'order' => 'DESC');
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<?php $terms = wp_get_post_terms( $post_ID, 'department' ); ?>
<?php global $post; $terms = wp_get_post_terms( $post->ID, 'department'); ?>
<div class="grid-item <?php echo $term->slug; ?> ">
<div class="staff-box">
<?php the_post_thumbnail('staff-member'); ?>
<a href="<?php echo the_permalink(); ?>">
<p class="staff-title"><?php the_title(); ?></p>
<p class="staff-job-title"><?php the_field('staff-job-title'); ?></p>
</a>
</div>
</div>
<?php endforeach;
wp_reset_postdata();?>
This is working using slug; ?> to display the class name however it is only displaying "veterinary-surgeons" on every single class name, when it should be displaying the relevant department on each item...
Hope that makes sense.
Many thanks.
</div>