categories - why get_the_post_thumbnail( the_ID()) echos extra post id

I have the following snippet which adds post thumbnails to products on archive page if matches a given product category,

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()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745393644a4625779.html

相关推荐

  • categories - why get_the_post_thumbnail( the_ID()) echos extra post id

    I have the following snippet which adds post thumbnails to products on archive page if matches a given product category,

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信