Support

Account

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>';
    					}
    				?>
    				
    				...