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

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 hardcodehard-code the ID in place of "$term_id"$term_id everything works as expected, but of course that doesn't help in a template.

For reference, my taxonomy is "Organizations"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; ?>

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 hardcode 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; ?>

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; ?>
Source Link
Adam
  • 13
  • 3

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 hardcode 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; ?>