0

I'm trying to order my custom posts by lower price to the higher price (numeric value). Here is my query to do that. But it's not ordering by lowest to highest price.

<?php
$tours = new WP_Query(array(
                'post_type'     => 'tour',
                'posts_per_page'=> 12,
                'meta_key' => 'tour_price',
                'orderby' => 'meta_value_num',
                'order' => 'DESC'
            ));

The avobe query only ordering the posts by descending order, not ordering by price.

0

I think that what you're looking for is this:

<?php
$tours = new WP_Query(array(
                'post_type'     => 'tour',
                'posts_per_page'=> 12,
                'meta_key' => 'tour_price',
                'orderby' => 'meta_value_num',
                'order' => 'ASC'
            ));

Descending means going down, as in, high to low.
Ascending is going up, low to high.

  • I already tried that. It's only ordering the posts by descending or ascending order, not ordering by price. – Eh Jewel Aug 2 '17 at 11:24
  • And with "ordering the posts […] not by price" you mean they're ordered by post title or something? – swissspidy Aug 2 '17 at 11:35
  • try adding meta_type => DECIMAL. If that doesn't work, the meta value might of your posts might not be numeric. – Connor Aug 2 '17 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.