【问题标题】:Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday上周星期一和下周星期一之间按最喜欢和发布的顺序排序
【发布时间】:2018-05-28 18:27:36
【问题描述】:

我有一个按最喜欢的内容对内容进行排序的代码,但我希望它显示前一周星期一和下周星期一之间最喜欢的内容。并且帖子必须在该时间范围内发布。我不知道如何按发布日期排序,并且在那个时间范围内最喜欢。如果有人可以,感谢您的帮助。

$loop = new WP_Query(
        array(
            'posts_per_page' => 6,
            'post_status' => 'published',
            'post_type' => 'post',
            'orderby' => 'meta_value_num',
            'meta_key' => '_liked',
                'date_query' => array(
                array(
                    'after' => strtotime( 'monday previous week' ),
                    'before' => strtotime( 'monday next week' )
                ),
            ),
            'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
        )
    );
while ($loop -> have_posts()) : $loop -> the_post();

【问题讨论】:

  • 您是否至少正确获取了数据?
  • 不,我只是按喜欢的次数正确排序,日期根本不起作用。

标签: php wordpress sorting posts


【解决方案1】:

好的,刚刚完成。以防万一有人需要。

                <?php         

                $loop = new WP_Query(array(
                                'posts_per_page' => 6,
                                'post_status' => 'publish',
                                'post_type' => 'post',
                                'orderby'  => array('meta_value_num' => 'DESC', 'date' => 'DESC'),
                                'meta_key' => '_liked',
                                    'date_query' => array(
                                     array(
                                    'after' => 'monday previous week',
                                    'before' => 'monday next week'
                                       ),
                                     ),
                                'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
                                     ));
                  while ($loop -> have_posts()) : $loop -> the_post();
            ?>

                <?php
                    /* Include the Post-Format-specific template for the content.
                     * If you want to overload this in a child theme then include a file
                     * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                     */


                    get_template_part( 'content', get_post_format() );              
                ?>

【讨论】:

    猜你喜欢
    • 2012-11-27
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    相关资源
    最近更新 更多