0

I am trying to figure out sorting posts with prices in one meta query, so the posts without prices are shown last, when ordered by ASC and not first.

Right now I am temporarily not showing posts without prices but it can't be left like that.

$args = array(
        'post_type' => 'inwestycja',
        'post_status'    => 'publish',
        'meta_key'      => 'price',
        'meta_type' => 'NUMERIC',
        'orderby'      => 'meta_value_num',
        'meta_value' => 1,
        'meta_compare' => '>',
        'order'        => 'ASC',
        'tax_query' => array(
            array (
                'taxonomy' => 'inwestycje',
                'field' => 'id',
                'terms' => $tax->term_id,
            )
        ),
        'posts_per_page' => 24,
        'paged' => $paged,
    );

Any suggestion how to approach such a problem, without extra work on front end. Extra switches for empty posts with empty prices and so on. Automatic solution :)

Problem is that ASC sorts posts with no price as cheapest, so they are first :)

2
  • I think you should probably just remove all the meta_ args like meta_key, and then use the meta_query arg instead. See my answer here and try to implement the solution in your code.
    – Sally CJ
    Commented Sep 24, 2021 at 2:43
  • Christine Cooper, why have you deleted my follow up to my own question ? This is the code that helped me sort out my original problem
    – Mastafu
    Commented Sep 30, 2021 at 11:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.