Support

Account

Home Forums General Issues Difficulty displaying Taxonomy Values

Unread

Difficulty displaying Taxonomy Values

  • Hi all,

    I’m tearing my hair out over this. I’m staring at my code trying to work out where I’m going wrong, and I’m having difficulties picking it.

    I’m trying to update the sidebar of my theme to display the contents of the fields I have set up. The logic I’m trying to set up is that it only displays details about a field if it contains a value, and ignore empty fields. I’ve got that working with the URL fields and Text fields. However I’m having issues with the Taxonomies.

    I’m using the following code:

    $terms = get_field( "genre", $post_id );
    if( $terms ) {
        echo "<b>Genre:</b> ";
        foreach( $terms as $term ) :
            echo esc_html( $terms->name );
        endforeach;
        echo "<br />";
    }

    The issue that I’ve got is that it displays the “Genre:” label, so it is obviously correctly picking up a value. IT doesn’t actually display the value of the field though.

    I was attempting to base this off https://www.advancedcustomfields.com/resources/taxonomy/ to try and work out how to use this correctly.

    I’m tearing my hear out trying to work out what I’m doing wrong. I’m sure it’s something dead simple that I’m not getting out of frustration. Hopefully somebody is able to offer some pointers as to what I’m doing wrong.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.