I'm in need of some help.
I want to display the category image on the current category page, and I have googled this, and each answer I find uses the same code.
They all use get_woocommerce_term_meta
to retrieve the ID of the thumbnail used so that you can then use wp_get_attachment_url
to get the image address.
All sounds great, but whenever I try this code it returns nothing, and I think that it is because get_woocommerce_term_meta
is deprecated.
Does anyone know of a way round this, so I can get the image address when I have the category ID?
This is the code that I have in place:
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
echo $cat->term_id."<br />";
echo $thumbnail_id;
$image_src = wp_get_attachment_url($thumbnail_id);
$cat->term_id
returns the correct ID of the category, but $thumbnail_id
returns 0.
The code is in header.php.
get_woocommerce_term_meta()
may be deprecated however it hasn't yet been removed. The issue is elsewhere in your setup.
With that said we can resolve the deprecation issue quite easily. Simply replace usages of get_woocommerce_term_meta()
with the new native WordPress function get_term_meta()
.
get_woocommerce_term_meta()
will simply pass its arguments on to the new function anyway so we can be sure the problem isn't with the deprecated function.
Likely causes of the issue:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With