I'm trying (but failing) to create 'Best Sellers' and 'New Releases' pages for my website. I'm using WP-Ecommerce 3.8.4 with WP 3.1.3 and I've gotten close but can't seem to get it right. Any help on this would be greatly appreciated...

I've added the following code to wp-ecommerce>wpsc-includes>product-template.php (original code from here):

//Popular products function
function popular_products ( $atts ) {
//Expose the Db to the function
global $wpdb;
//Get the results
$pp = $wpdb -> get_results ( "SELECT prodid, SUM(quantity) FROM {$wpdb->prefix}wpsc_cart_contents GROUP BY prodid ORDER BY quantity DESC LIMIT {$atts['limit']}", ARRAY_A);
//Loop through the results
foreach ( $pp as $item ) {
//Output it
<img alt="<?php echo wpsc_the_product_title ( null, null, $item['prodid'] )?>" src="<?php echo wpsc_the_product_thumbnail ( null, null, $item['prodid'] )?>" />
<?php echo wpsc_the_product_title ( $item['prodid'] )?>
add_shortcode ( 'dm_popular', popular_products ); 


I've then added [dm_popular limit=5] to the best sellers page (http://www.iconiccanvasart.co.uk/best-sellers) but as you can see it's not quite working properly:

  1. one product can appear multiple times if it's been ordered in different variations.
  2. it isn't retrieving the Products title properly (all are outputted as 'Best Sellers').
  3. Ditto for the image Alt tags.
  4. I've not added a URL to the products yet as not sure how to at the moment.

Once I've this working I'm hoping to alter slightly and have a 'New Releases' page based on a similar query (so any help on this may help to killing two birds with one stone).

Any help would be greatly appreciated.


EDIT: I've since managed to get this all working bar the price and product text - final code can be viewed here: http://getshopped.org/forums/topic/bestselling-products/

  • 2
    There's a Support Forum at the plugins homepage...
    – kaiser
    Jun 25, 2011 at 19:14
  • These two accounts seem to be of one person, would you like them to be merged?
    – Rarst
    Aug 2, 2011 at 17:05
  • yes please, I had trouble with the openid so started using my google account now. Thanks buddy
    – Dean Rowe
    Aug 12, 2011 at 20:10

1 Answer 1


wpsc_the_product_title is just a wrapper for get_the_title, and it doesn't take any arguments.

Call setup_postdata( $item['prodid'] ) at the start of your foreach loop, and then the function should perform as expected.

  • thank you TheDeadMedic - I was calling the wrapper in a few instances. It's still not working perfectly but I think that's to do with the SQL code. I'll work on this and post final code if I get it working. Thanks again ChainsawDR
    – Dean Rowe
    Jun 26, 2011 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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