I'm working on a conditional statement to either output only the post thumbnail or a post thumbnail and a link for a custom post.
The output is based on a check if the post uses a specific taxonomy ID.
Getting the taxonomy ID of the post isn't an issue, however creating the conditional statement is.
This is the current code:
<?php $term = get_the_terms( $post_object->ID, 'my_taxonomy_name' );
// This if statement has to be incorrect
if($term->term_id == 4 ):?>
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_post_thumbnail($post_object->ID, 'full'); ?></a>
// It always returns the following
<?php else:?>
<?php echo get_the_post_thumbnail($post_object->ID, 'full'); ?>
<?php endif;?>
This is the output of var_dump($term);
array(1) { [0]=> object(WP_Term)#10440 (10) { ["term_id"]=> int(4) ["name"]=>
string(4) "Case" ["slug"]=> string(4) "case" ["term_group"]=> int(0)
["term_taxonomy_id"]=> int(4) ["taxonomy"]=> string(16) "soort_referentie"
["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(2)
["filter"]=> string(3) "raw" } }
Any pointers to help me solve this issue are much appreciated.
Updated code with the solution:
$terms = get_the_terms( $post_object->ID, 'my_taxonomy_name' );
foreach($terms as $term){;
if($term->term_id === 4 ):?>
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_post_thumbnail($post_object->ID, 'full'); ?></a>
<?php else:
echo get_the_post_thumbnail($post_object->ID, 'full');
break;
endif;
}