I want to display thumbnails of multiple categories on a page, i am having hard time accessing the categories as it shows empty. is something wrong with my code?

                  $args = array(
                        'per_page' => '12',
                         'category_name' => 'travel',
                         'orderby' => 'title',

                    );


print_r($args); //nothing gets output, like categories
$query = new WP_Query( $args );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();

    print_r($args); //nothing gets output, like categ

    //want to display the thumbnail

endwhile;;
    endif;

2 Answers
2

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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *