按多个变量(META_KEY和发布日期和时间)对帖子进行排序

时间:2016-09-18 作者:user5849394

在cascadeoc。组织/结果我有按自定义字段“event\\u date\\u results”排序的结果,该字段是事件发生的日期(而不是帖子发布的日期)。但是,当同一天有多个结果时,我想通过发布日期和时间进一步控制后期排序。如何添加此第二个orderby筛选器?

以下是我所拥有的:

<?php

    $query = new WP_Query( array(

        \'post_type\' => \'result\',
        \'posts_per_page\' => 100,
        //\'paged\'          => $paged,
        \'meta_key\'   => \'event_date_results\',
        \'orderby\'    => \'meta_value_num\',
        \'order\'      => \'DESC\',
        \'meta_value\'    => date(\'Ymd\'),
        \'meta_compare\'  => \'<\',
        \'date_query\'    => array(
            array(
                    \'key\' => \'date\',
                    \'value\' => date(\'Ymd\'),
                    \'compare\' => \'<\', //less than
                    \'type\' => \'DATETIME\'
                )
            ),

        ) );

    ?>

1 个回复
SO网友:user5849394

我找到了关于“的链接”a more powerful ORDER BY in WordPress 4.0“这让我尝试了以下代码:

        <?php

    $query = new WP_Query( array(

        \'post_type\' => \'result\',
        \'posts_per_page\' => 100,
        //\'paged\'          => $paged,
        \'meta_key\'   => \'event_date_results\',
        \'orderby\'    => array( \'meta_value_num\' => \'DESC\', \'post_date\' => \'DESC\'),
        //\'order\'      => \'DESC\',
        \'meta_value\'    => date(\'Ymd\'),
        \'meta_compare\'  => \'<\',
        \'date_query\'    => array(
            array(
                    \'key\' => \'date\',
                    \'value\' => date(\'Ymd\'),
                    \'compare\' => \'<\', //less than
                    \'type\' => \'DATETIME\'
                )
            ),

        ) );

    ?>
“orderby”行是我唯一更改的内容(并且我注释掉了我的另一个“DESC”行……现在可以删除它了。)

。。。别介意我的“翻页”评论。。。我还在想如何给这个分页

相关推荐

如何在WooCommerce_Account_Orders函数中传递$CURRENT_PAGE?

woocommerce功能woocommerce_account_orders($current_page) 已调用1个参数$current_page. 该函数通过调用woocommerce_account_orders_endpoint 通过以下挂钩-add_action( \'woocommerce_account_orders_endpoint\', \'woocommerce_account_orders\' );然而,在上述挂钩中,$current_page 未在函数中作为参数传递。情况如何$c