Skip to main content
2 of 2
added 1 character in body
Johansson
  • 15.4k
  • 11
  • 43
  • 79

How to Retrieve a Taxonomy Term's ID?

I am trying to display a taxonomy term's image and need the term's ID. For some reason I am having trouble getting the ID. If I hard-code the ID in place of $term_id everything works as expected, but of course that doesn't help in a template.

For reference, my taxonomy is Organizations and each entry is the name of an organization.

This is the first time I've really gotten into WordPress functions and templates.

Here's what I have:

    <?php 

      $terms = get_field('listing_organization');
      $term_id = get_queried_object_id();

      if( $terms ): ?>

        <ul>

        <?php foreach( $terms as $term ): ?>
          <img src="<?php echo z_taxonomy_image_url($term_id, thumbnail); ?>" />
          <h2><a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a></h2>
          <p><?php echo $term->description; ?></p>

        <?php endforeach; ?>

        </ul>

    <?php endif; ?>
Adam
  • 13
  • 3