Title: Shortcode sort by SKU
Last modified: August 21, 2016

---

# Shortcode sort by SKU

 *  Resolved [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * (@jmessick9)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/)
 * I have a client that needs to have the category shortcode sort the products by
   sku. Here is the shortcode that I would like to use. Any idea on how I can do
   this?
 * [wpsc_products category_url_name=’pir-zia-inayat-khan-recordings’ sort_order=’
   product_sku’]
 * [http://wordpress.org/plugins/wp-e-commerce/](http://wordpress.org/plugins/wp-e-commerce/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * (@jmessick9)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066189)
 * Any ideas on how to sort by sku on the category list?
 *  [Mihai Joldis](https://wordpress.org/support/users/misulicus/)
 * (@misulicus)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066193)
 * According to the code in the files these are the only parameters that can be 
   passed to sort_order
 * // name,dragndrop,price,ID,author,date,title,modified,parent,rand,comment_count
 *  Thread Starter [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * (@jmessick9)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066194)
 * would you know or have any idea to add the ability to sort by SKU?
 *  [vark](https://wordpress.org/support/users/vark/)
 * (@vark)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066195)
 * hi,
    if you’re seriously into code, i have a solution which may be adaptable 
   for your use. You can contact me via the support link on my website, and I’ll
   send you what i have.
 *  Thread Starter [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * (@jmessick9)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066196)
 * Thanks!
 *  Thread Starter [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * (@jmessick9)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066206)
 * I resolved this issue. Thank you to Varktech for the code hints.
 * I changed the wpsc-list_view.php file to show a list of products, creating table
   headers.
    **Added the code to show the sku in the list:**
 * `<?php echo get_post_meta(wpsc_the_product_id(), '_wpsc_sku', true); ?>`
 * **Added a case to the wpsc-functions.php wpsc_product_sort_order_query_vars around
   line 826:**
 *     ```
       case "sku":
   
       			add_filter( 'posts_join_sku', 'wpsc_add_meta_table_sku' );
       			add_filter( 'posts_where_sku', 'wpsc_add_meta_table_where_sku' );
       			$query_vars["meta_key"] = '_wpsc_sku';
       			$query_vars["orderby"] = '_wpsc_sku';
       			break;
       ```
   
 * **after the function I added the $where and $join statements:**
 *     ```
       function wpsc_add_meta_table_where_sku($where){
       	global $wpdb;
   
       	remove_filter( 'posts_where_sku', 'wpsc_add_meta_table_where_sku' );
   
       	return $where . ' AND ' . $wpdb->postmeta . '.meta_key = "_wpsc_sku"';
       }
   
       /**
        * add meta table join section for ordering by sku
        *
        */
       function wpsc_add_meta_table_sku($join){
       	global $wpdb;
       	remove_filter( 'posts_join_sku', 'wpsc_add_meta_table_sku' );
       	if(strpos($join, "INNER JOIN ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id)") !== false){
       		return  ' JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts. '.ID = ' . $wpdb->postmeta . '.post_id';
       	}else{
       		return $join;
       	}
       }
       ```
   
 * Only reason I posted this is for anyone else that may need to do something similar
   in the future. I hope it helps, as I could not find or get help other then from
   varteck.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Shortcode sort by SKU’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-e-commerce_ebebeb.svg)
 * [WP eCommerce](https://wordpress.org/plugins/wp-e-commerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-e-commerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-e-commerce/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-e-commerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-e-commerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-e-commerce/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [jmessick9](https://wordpress.org/support/users/jmessick9/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/shortcode-sort-by-sku/#post-4066206)
 * Status: resolved