I'm trying to output slugs as class names for all of the taxonomies that a post is attached to, so I can filter those posts using MixItUp3 with the Multifier Extension on a custom directory page.
I have a custom loop setup that only pulls through directory posts that have been tagged 'current' (this allows old listings to remain in the system but not be displayed).
<?php
$args = array(
'post_type' => 'directory',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'directory_cat',
'operator' => 'EXISTS'
),
array(
'taxonomy' => 'directory_tag',
'field' => 'slug',
'terms' => 'current'
)
)
);
$query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<div class="column mix<?php if ($class_names) { echo ' ' . $class_names;} ?>">
<a href="<?php the_permalink(); ?>">
...
</a>
</div>
I'm trying to output the slugs into the div class as shown above ($class_names), but I can't find the right way to do it. The following code was taken from the MixItUp documentation and I've tried to edit it to my needs but as a php beginner I just keep faltering.
$taxonomies = get_terms();
$slugs = wp_list_pluck($taxonomies, 'slug');
$class_names = join(' ', $slugs);
It outputs and formats correctly but it lists every taxonomy in the system, rather than the ones attached to each post in the loop.