Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
?>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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";
    }
    ?>
share|improve this answer
    
I <3 you Sky!!! –  kristina childs Aug 2 '13 at 5:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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