I am trying to order my products by discount-amount.
I have saved the discount as a number in my post-meta called “discount”, but when I use the following code:
$productArgs = array( 'posts_per_page' => 20, 'post_type' => 'product', 'meta_key' => 'discount', 'orderby' => 'meta_value_decimal', 'order' => 'DESC', 'meta_type' => 'DECIMAL', ); $test = $productArgs; $products = get_posts($productArgs);
The products are displayed like: 0%, 50%, 55%, 28%.
Even if I change the
order to ASC, nothing happens to the output.
I have also tried
'orderby' => 'meta_value, and without the
Does anyone have an idea what can be causing this?
Read more here: WordPress Orderby wont order posts