Suddenly starting getting this error for the following code:
<?php foreach (get_the_terms(get_the_ID(), 'loan-club') as $cat) : ?>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" title="ON LOAN AT: <?php echo $cat->name; ?>" />
<?php endforeach; ?>
Sometimes the taxonomy 'loan-club' is empty. Could that be the problem? If so, could someone point me towards the correct code?
Add
if
condition beforeforeach
:Look at get_the_terms() function in the documentation: https://developer.wordpress.org/reference/functions/get_the_terms/
The function may also return WP_Error or false. If WP_Error or false is returned this will cause the error and the foreach loop breaks.