[英]How to fetch the woocommerce product image from wp_query
嗨,我用下面的代码来填充woocommerce产品标题的下拉列表
<select Name='choose' id="chooseme">
<?php
$args = array( 'post_type' => array('product') ,'posts_per_page' => 100);
$loop = new WP_Query( $args );
;
while ( $loop->have_posts() ) :
$loop->the_post();
echo '<option selected value="'.the_title().'</option>';
endwhile;
?>
</select>
现在,我想从此查询中获取产品图片。 是否可以从此代码中获取图像,或者有其他解决方案吗?
您只需要使用get_the_post_thumbnail()
:
echo get_the_post_thumbnail($loop->post->ID, 'yourTable');
在while()
的体内
例:
while ($loop->have_posts()) : $loop->the_post();
echo get_the_post_thumbnail($loop->post->ID, 'yourTable');
endwhile;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.