1

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

2 Answers 2

2

The term ID is contained within the term object you are already using in your loop:

echo z_taxonomy_image_url( $term->term_id, 'thumbnail' );
0
0

Are you using this on an archive page?

Try to get the term ID with this instead:

$queried_object = get_queried_object(); 
$term_id = $queried_object->term_id;
5
  • I'm not having luck with that. It's not an archive page. I have it set up where a company's page displays the organizations that the company belongs to in addition to other company info.
    – Adam
    Commented Jul 12, 2017 at 17:46
  • in what template are you using this?
    – dbeja
    Commented Jul 12, 2017 at 17:46
  • The template is custom to the theme I'm using (Listify). The template itself is called 'content-single-job_listing.php'
    – Adam
    Commented Jul 12, 2017 at 17:50
  • that's a taxonomy template? Commented Jul 12, 2017 at 18:01
  • that's a page template used by the theme.
    – Adam
    Commented Jul 12, 2017 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.