最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - Stuck in Order by more then one

programmeradmin1浏览0评论

I want to orderby post by 2 custom fields and alphabetical here is my code

'meta_query'    => array(
    array(
        'relation' => 'AND',
        'awards' => array(
            'key'       => 'awards',
            'compare'   => 'EXISTS',
        ),
        'points' => array(
            'key'       => 'points',
            'compare'   => 'EXISTS',
        ),
    ),
),
'orderby' => array(

    'awards'       => 'desc',
    'points'     => 'desc',
),

So if the awards are same so it will order by points but if the points will same also so it will orber by alphabetical.

I want to orderby post by 2 custom fields and alphabetical here is my code

'meta_query'    => array(
    array(
        'relation' => 'AND',
        'awards' => array(
            'key'       => 'awards',
            'compare'   => 'EXISTS',
        ),
        'points' => array(
            'key'       => 'points',
            'compare'   => 'EXISTS',
        ),
    ),
),
'orderby' => array(

    'awards'       => 'desc',
    'points'     => 'desc',
),

So if the awards are same so it will order by points but if the points will same also so it will orber by alphabetical.

Share Improve this question asked Sep 28, 2019 at 18:32 HammadHammad 413 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You've got the unnecessary array involved around clauses. The correct code is

'meta_query' => array(
    'relation' => 'AND',
    'awards_clause'   => array( // clause
        'key'     => 'awards',
        'compare' => 'EXISTS',
    ),
    'points_clause'   => array( // clause
        'key'     => 'points',
        'compare' => 'EXISTS',
    ),
),
'orderby'    => array(
    'awards_clause' => 'DESC',
    'points_clause' => 'DESC',
),
发布评论

评论列表(0)

  1. 暂无评论