Home › Forums › Front-end Issues › get the feature img from post objects › Reply To: get the feature img from post objects
Many tks, @elliot.
Still got a problem. As the code demo above, the link target right, but the thumbnail shown nothing. I’m sure the target post thumbnail was set.
There are TWO custome field set, checkbox and post object, they will work well?
I custom a post type “product”, and set a taxonomy “product_category” for it, the code is placed in the loop of taxonomy-product_category.php. My code following:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article>
<h1></h1>
<?php
the_content();
// FIRST CUSTOM FIELD: CHECKBOX FIELD
$values = get_field( 'feature' );
if ($values) {
foreach( $values as $value ) {
echo '<span class="label label-feature">' . $value . '</span>'; //WORKING WELL
}
}
// SECOND FIELD: POST OBJECT
$related_1 = get_field( '1_related_product' );
if( $related_1 ) {
echo '<a href="' . get_permalink( $related_1 ) . '">'; // WORKING WELL
echo get_the_post_thumbnail( $related_1 ); // RETURN NOTHING
echo '</a>';
}
?>
...
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.