Support

Account

Home Forums General Issues display taxonomy term name

Solving

display taxonomy term name

  • Hi all,

    I am working with ACF 4.3.4, WP 3.8.1

    I have a custom post type of Inventory with a custom taxonomy of Condition. I have a custom taxonomy field (single select) set up for Trailer Condition.

    I am simply trying to display the Condition term name on a single inventory post using the code on this page:
    http://www.advancedcustomfields.com/resources/field-types/taxonomy/

    Here is the code in the template:

    <?php $term = get_field('trailer_condition');
    if( $term ): ?>
    <div class="condition">Condition: <?php echo $term->name; ?></div>
    <?php endif; ?>

    But nothing displays for the term name.

    Here is the var dump for $term:
    array(1) { [0]=> object(stdClass)#429 (11) { [“term_id”]=> int(13) [“name”]=> string(4) “Used” [“slug”]=> string(4) “used” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(13) [“taxonomy”]=> string(9) “condition” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(1) [“object_id”]=> int(117) [“filter”]=> string(3) “raw” } }

    Any thoughts on what I am doing wrong?

    Thank you

    Terry

  • This reply has been marked as private.
  • Hi @tcnolan7

    Your var_dump shows that $term is actually an array. Did you choose a multi-select field type for the taxonomy field?

    You will need to loop over the terms and output them each – even if there is only 1.

    Thanks
    E

  • Any code examples to help others out who are having troubles with this as well?
    The documentation on custom taxonomies is very limited btw!

  • Hi,

    This is what worked for me. My custom field was a single select. I had to use the following to display the term:

    <?php $term = get_field('trailer_condition');
    if( $term ): ?>
    <div class="trailercondition">Condition: <?php echo $term[0]->name; ?></div>
    <?php endif; ?>

    Hope that helps.

  • Hello,

    I have the same problem but how would I make it work with the Visual Composer element ? I am trying to display the Taxonomy names

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘display taxonomy term name’ is closed to new replies.