admin管理员组

文章数量:1426023

I have the following snippet which adds post thumbnails to products on archive page if matches a given product category, which will output the image but echos the the post id as well. How do I suppress to not show post id?

add_action( 'woocommerce_after_shop_loop_item_title', function () {
    if(is_product_category('t-shirts')) {
        $thumb = get_the_post_thumbnail( the_ID());
        if(is_string($thumb) ) {
            echo '<div class="imagewrapper">' . $thumb;
        }
    }

}, 9 );
add_action( 'woocommerce_after_shop_loop_item_title', function () {
    if(is_product_category('t-shirts')) {
        $thumb = get_the_post_thumbnail( the_ID());
        if(is_string($thumb) ) {
            echo '</div>';
        }
    }
}, 11 );

I have the following snippet which adds post thumbnails to products on archive page if matches a given product category, which will output the image but echos the the post id as well. How do I suppress to not show post id?

add_action( 'woocommerce_after_shop_loop_item_title', function () {
    if(is_product_category('t-shirts')) {
        $thumb = get_the_post_thumbnail( the_ID());
        if(is_string($thumb) ) {
            echo '<div class="imagewrapper">' . $thumb;
        }
    }

}, 9 );
add_action( 'woocommerce_after_shop_loop_item_title', function () {
    if(is_product_category('t-shirts')) {
        $thumb = get_the_post_thumbnail( the_ID());
        if(is_string($thumb) ) {
            echo '</div>';
        }
    }
}, 11 );
Share Improve this question asked Jun 17, 2019 at 14:05 fefefefe 8943 gold badges14 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I believe because:

the_ID() : Display the ID of the current item in the WordPress Loop.

and

get_the_ID() : Retrieve the ID of the current item in the WordPress Loop.

So the_ID() displays the post ID.
Try to use get_the_ID()

本文标签: categorieswhy getthepostthumbnail( theID()) echos extra post id