array - meta query or with meta value

admin2025-06-03  4

within one of my query_posts I use 'meta_key' => 'clpr_topcoupon', ;meta_value'=> 1, now I would like to show post without as well but the one with meta_value first. I tried:

'meta_query' => array(
   'relation' => 'OR',
    array( //check to see if date has been filled out
            'meta_key' => 'clpr_topcoupon',
                        'meta_value'=> 1,
        ),
      array( //if no date has been added show these posts too
            'meta_key' => 'clpr_topcoupon',
                        'meta_value'=> 0,
        )
    ),

However it is not working. It shows the one with 0 first.

within one of my query_posts I use 'meta_key' => 'clpr_topcoupon', ;meta_value'=> 1, now I would like to show post without as well but the one with meta_value first. I tried:

'meta_query' => array(
   'relation' => 'OR',
    array( //check to see if date has been filled out
            'meta_key' => 'clpr_topcoupon',
                        'meta_value'=> 1,
        ),
      array( //if no date has been added show these posts too
            'meta_key' => 'clpr_topcoupon',
                        'meta_value'=> 0,
        )
    ),

However it is not working. It shows the one with 0 first.

Share Improve this question asked Feb 3, 2019 at 16:39 joloshopjoloshop 211 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1
'meta_key' => 'clpr_topcoupon',
        'orderby' => 'meta_value_num',
        'order' => 'DESC'

You can solve the problem by using order by clause then there will no need to write meta query. Please use the above code to solve your problem.It will show the posts according to descending order of the value in meta key.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748947707a315066.html

最新回复(0)