Order by meta value
-
Hi Everyone,
I’m currently running a WP 3.8.1 install with WP E-Commerce plugin. The powers that be want to be able to sort their products to move out of stock items to the back of the line.
In the plugin, the stock is in the postmeta table under key “_wpsc_stock”. What I am trying to do is order the products by the meta_value of that key (either 1 or 0).
I have the filter in my functions.php, and it updates the existing query with whatever I put in.
add_filter( ‘posts_orderby’, ‘products_orderby’ );
function products_orderby( $orderby )
{
global $wpdb;
$orderby = $wpdb->postmeta . ‘.meta_value DESC, ‘ . $orderby;
return $orderby;
}I know this is incorrect, I need to know what I can put into the function to order this by the meta_value. I’ve been looking everywhere, seen every variation, and nothing seems to work.
Thanks!
- The topic ‘Order by meta value’ is closed to new replies.