Using the Enhanced Media Library plugin, I have added custom media categories and am now trying to apply those categories as classes for images shown in the [gallery] shortcode. This is the code I'm using (inside a custom [gallery] shortcode):
$terms = get_terms('media_category', array('parent' => '15'));
foreach ( $terms as $id => $term ) {
$term = $term->slug;
}
This code is outputting the category names as classes, however it's applying the categories only from the first image in the gallery to every single other image, and ignoring the categories of the other images.
As I have incorporated Isotope, I'm also using the media categories to sort the gallery. This code is working correctly:
$terms = get_terms('media_category', array('parent' => '15'));
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<button type='button' class='btn' data-hover='" . $term->name . "' data-filter='." . $term->slug . "'>" . $term->name . "</button>\n";
}
}
What is it I've missed on the first piece of code?