$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>array - meta query or with meta value|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

array - meta query or with meta value

matteradmin8PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far