WordPress Orderby wont order posts

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 'meta_type'.

Does anyone have an idea what can be causing this?

Read more here: WordPress Orderby wont order posts

Leave a Reply

Your email address will not be published. Required fields are marked *