3

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;
6

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.

4
  • nothing get output or displayed. if i do print_r($args) the array code return same as displayed above. – localhost Aug 26 '13 at 9:36
  • did you change the product category to your category slug? and if you do print_r($args) the array always output the same array keys and values. – Rahil Wazir Aug 26 '13 at 9:45
  • how do i know which parameters to give in args, do i look into database? like product_cat – localhost Aug 26 '13 at 11:06
  • No way. Try to google it, it will take you to the link. – Rahil Wazir Aug 27 '13 at 8:26
0

For product filter with 3 products and with Featured title:

$args = array(
    'post_type'      => 'product',
    'posts_per_page' => 3,
    'product_cat'  => 'Featured',
    'order_by' => 'title',
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.