fetch products if image is found in woocommerce?

对着背影说爱祢 提交于 2019-12-13 05:48:56

问题


i want to show image only products in woocommerce.

My fetch query is given below

$args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 9, 'orderby' =>'date','orderby' => 'rand' );
$loop = new WP_Query( $args );

how can i get the image products only?


回答1:


Are you looking for something like this ?

<?php 
    $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 9, 'orderby' =>'date','orderby' => 'rand' );
    $loop = new WP_Query( $args );
    while ($loop->have_posts()) : $loop->the_post();
        echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
    endwhile;
?>

UPDATED

$args = array( 
                'post_type' => 'product', 
                'stock' => 1, 
                'posts_per_page' => 9, 
                'orderby' =>'date',
                'orderby' => 'rand', 
                'meta_query'=>array(
                    array(
                        'key'=>'_thumbnail_id', 
                        'compare' => 'EXISTS'
                    )
                )
            );

Change arg to get product if it has feature image.



来源:https://stackoverflow.com/questions/29936457/fetch-products-if-image-is-found-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!