Displaying products from categories in woocommerce

You’re passing bad array keys to $args. Do something like this:

$args = array(
        'posts_per_page' => '12',
        'product_cat' => 'lead-generation',
        'post_type' => 'product',
        'orderby' => 'title',
    );


$query = new WP_Query( $args );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();

the_post_thumbnail('full');
    //want to display the thumbnail

endwhile;
    endif;

There is no per_page key, use posts_per_page instead.

Woocommerce category taxonomy slug is ‘product_cat’. The ‘category_name’ is for normals posts. You must target the post type of woocommerce, here it is product.

Leave a Comment