0

This is the file I'm working with:

    <?php
$class ='';
foreach ($consoles as $console) {
$class .= $console->slug . ' ';
} 
?>
<div id="<?php the_id(); ?>" class="<?php echo $class ?>>
Content
</div>




<?php
$consoles = wp_get_object_terms( $post->ID,  'consoles' );
$separator = ", ";
$output = '';

if ( ! empty( $consoles ) ) {
if ( ! is_wp_error( $consoles ) ) {
echo '<li><span>Platforms:</span> ';
foreach( $consoles as $term ) {
$output .= esc_html( $term->name ) . $separator;
} echo trim($output, $separator);
echo '</li>';
}
}
?>
  • 1
    Please post only relevant code, there is so much irrelevant code that is distracts one from the actual issue – Pieter Goosen Jun 17 '16 at 9:54
0

You can easily just get the taxonomies you need with wp_get_object_terms, and than do something like

$class ='';
foreach ($genres as $genre) {
    $class .= $genre->slug;
} 

Do this for each of your taxonomies,than just echo $class.

  • This is really close, however the first post doesn't output the taxonomy, but the second does, but it's wrong, that taxonomy should be for the first one. Each taxonomy on a post should be for the one before it. Also how can I add a space inbetween if there's more than one? – Darren Bachan Jun 17 '16 at 19:24
  • $class .= $console->slug . ' '; I managed to space them with this, so the main problem now is that each post is showing the taxonomy of the post before. – Darren Bachan Jun 17 '16 at 19:39
  • You should put <?php $consoles = wp_get_object_terms( $post->ID, 'consoles' ); at the beginning of your code - in your current code $consoles is undefined at the beginning. – user1049961 Jun 22 '16 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.