foreach error on false boolean from get_terms

What you need is pretty much straight out of the Codex:

$terms = get_the_terms( $post->ID, 'on-draught' );

if ( $terms && ! is_wp_error( $terms ) ) : 

    $draught_links = array();

    foreach ( $terms as $term ) {
        $draught_links[] = $term->name;
    }

get_the_terms() can return a term object, false, or a WP_Error object. You are checking for neither the false nor the error object. That is what this conditional does:

if ( $terms && ! is_wp_error( $terms ) ) 

Use it instead of if(is_array($terms)){

Leave a Comment