Reputation: 156
I'm developing a site with WP Ecommerce and I'd like to show all products within a certain category on the home page as a simple way to do "featured products".
The problem I'm having is that the query is just returning ALL products rather than those within the single category. Right now I'm using this code that I found somewhere through Google:
$args = array(
'post_type' => 'wpsc-product',
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'homepage-featured'
));
$wp_query = new WP_Query( $args );
while( $wp_query->have_posts() ) : $wp_query->the_post();
(etc...)
I've also tried using the standard get_posts function with "'category' => 3" since WPEC seems to store all the product data in the standard Wordpress post format, but that returned nothing. If I used "'category' => 'cat_slug'" or "'category' => 'full_cat_name'" it just returned all products again.
Anyone know how this works?!
Cheers, -- Ben.
Upvotes: 0
Views: 900
Reputation: 21
I've recently had to implement a similar category filter to the main shop, here is your original code modified;
$args = array(
'post_type' => 'wpsc-product',
'tax_query' => array(
array(
'taxonomy' => 'wpsc_product_category',
'field' => 'slug',
'terms' => 'homepage-featured'
)
)
);
$wp_query = new WP_Query( $args );
Note the modified taxonomy wpsc_product_category specific to WP eCommerce, and the nested array within the tax_query array, as the WP_Query class allows for multiple taxonomy queries.
For a full list of possible parameters and features with WP_Query, have a look at; http://codex.wordpress.org/Class_Reference/WP_Query
Upvotes: 1