0

I feel like I'm this close but can't figure out if it's a synax or variable thing. I'm tring to echo the slug to auto-populate the corresponding image.

<?php

    $terms = get_the_terms( $post->id, 'series', array( 'parent' => 0 ) ); 
    $terms_slugs = array();
    foreach( $terms as $term ) {
        $terms_slugs[] = $term->slug; 
    }

    if( !empty($terms_slugs) ) :
      echo "/assets/products/" . $terms_slugs. "/logos/" .$terms_slugs . "-logo.png" ;
    endif;
?>
2

Here's the correct syntax for what you're trying to do, if there's just the single value for the 'series' custom taxonomy slug that you're trying to retrieve. You were passing the whole array to your echoed string. I made a new variable $series which pulls the first/only value in the $terms_slugs array. And simplified a few other things you didn't need in there. :)

    <?php 
    $terms = get_the_terms( $post->ID, 'series' );
    if ($terms) {
        $terms_slugs = array();
        foreach ( $terms as $term ) {
            $terms_slugs[] = $term->slug;
        }
        $series = $terms_slugs[0];      
        echo "/assets/products/{$series}/logos/{$series}-logo.png";
    } else {
        echo "nothing to see here";
    }
    ?>
| improve this answer | |

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.