WooCommerce Sort by Meta Key Value
Today’s discussion is centered on WooCommerce Sort by Meta Key Value. Today, we will talk about how to sort by meta key values. Upon working with WooCommerce, we have realized that one cannot simply sort by meta key values. The reason being stated is that for numeric, it is treated as a string. After much research, we came to the conclusion that (meta_value_num) will do the work quite well. So, we are sharing this trick with you here.
Below is an example:
$queryargs = array(
'post_type' => 'product',
'meta_key' => 'meta_key',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
'post_type' => 'product',
'meta_key' => 'meta_key',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);