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

custom post types - Orderby if between two meta fields

programmeradmin0浏览0评论

I am trying to orderby my CPT if the current time is in between two meta fields. (i.e, the current_time() is between two time fields.).

meta_query returns only the posts that are between the values, but not all posts. Here is what I have tried.

    $args['meta_query'] = array(
        array(
            'key' => 'open_today',
            'value' => strtolower(current_time('l')),
        ),
        array(
            'key' => 'open_time',
            'value' => current_time(),
            'compare' => '>='
        ),
        array(
            'key' => 'close_time',
            'value' => current_time(),
            'compare' => '<'
        ),
    );

Basically what I am trying to achieve is that sort restaurants by open time. So, when a user selects to sort the listing by Open Now, the query returns the resturants open now at first and then rest of them.

发布评论

评论列表(0)

  1. 暂无评论