3

I have a code which sorts the content by most liked, but I would like it to show the most liked in between previous week monday and next week monday. And the posts must be published in that time frame. Tho I have no idea how to sort by published date and most liked in that time frame. Grateful for help if anyone can.

$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();
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98

1 Answers1

0

Ok just finished it. In case anyone needs this.

                <?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() );              
                ?>