C
C
chelnokov_a2020-09-20 20:36:53
WordPress
chelnokov_a, 2020-09-20 20:36:53

How to get id of all subcategories in woocommerce archive?

Hello. I want to display the image of subcategories with the get_the_post_thumbnail() function in the content_product_cat.php file.
How to get id to specify it in function parameter?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Zolin, 2020-09-20
@artzolin

Yes, you won’t be able to do this, it takes the id of the post, and you are in the
5f67958e0af42453725036.png
Use categorywp_get_attachment_image()

A
Anton Litvinenko, 2020-09-20
@AntonLitvinenko

I was getting the category image on the archive page something like this

<?php 
  if ( is_product_category() ){
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
    $image = wp_get_attachment_url( $thumbnail_id ); 
    if($image) {
      echo '<div class="title-img"><img src="' . $image . '" alt="' . $cat->name . '" /></div>';
    }
  }
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question