0

kind of struggling with a task but also writing to see if what i'm doing makes sense. Simple question is I can't return the thumbnail in a foreach loop.

Background is I am using a taxonomy to map investor/investee relationships, so if entity A invests in entity B,C,D then A should list B,C,D as Investments on A's summary page and B,C,D should list A as Investor on their respective pages. Any number of combinations also possible. So I decided to use one flat Taxonomies investments. Goal is to show the loop on the summary page of each entity listing the investments.

I am using get_the_terms to return taxonomy term name slugs. The slug of the overall taxonomy has a rewrite to match the custom post type so the echo'd link below takes you to each entities summary page ie "www.example.com/customposttype/taxonomy-name(A or B or C or D)". This works to return the link but not sure if this is a good approach, I realize I'm not actually returning the post ID but building the links and hence the issues getting the thumbnails. Hope this was not too long and makes some sense, been thinking maybe overthinking this. Any direction or thoughts appreciated.

<?php

// Get the terms
$terms = get_the_terms( $post->ID, 'inv_org' );

if ( $terms && ! is_wp_error( $terms ) ) { ?>

    <div class="col mt-1">
    <div class="card">
        <div class="card-body">
           <h5 class="card-title">Title</h5>

            <ul class="list-group">
                <?php
                  foreach ( $terms as $term ) { ?>
                    <li class="list-group-item border-0">


                    <?php  echo '<li><a href="'.get_term_link($term->slug, 
                      'inv_org').'">'.$term->name.'</a></li>'; ?>

                    </li><?php
                }

                ?>
            </ul>
        </div></div></div><?php
}

?>
  • Let's check, if I understood your question correctly. Inside your foreach loop you want to get the post_thumbnail of a cpt, which is assigned to the $term that is the current loop iteration, right? – Antti Koskinen Oct 21 '18 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.