Support

Account

Home Forums ACF PRO Posts from current week using date picker value

Solved

Posts from current week using date picker value

  • I’m building a weekly leaderboard and trying to display posts from only the current calendar week Monday to Sunday using a date logged using the date picker field.

    Currently, I’ve made it thus far, but can’t figure out how to only show posts from the current calendar week:

     $args = array(
            'meta_query' => array(
                array(
                    'key' => 'date_of_ride',
    
                )),
            'post_type' => 'ride', 'posts_per_page' => 10, 'order' => 'DEC',
        );
        $leaders = new WP_Query( $args );
    

    Any help appreciated,
    Thanks

  • Solved it! Tackled it in a different way.

        <?php
        $args = array(
            'date_query' => array(
                array(
                    'after' => '-' . (intval(date('N')) - 1) . 'days',
                    'inclusive' => true
                )
            ),
            'post_type' => 'ride', 'posts_per_page' => 10, 'orderby' => 'meta_value_num', 'order' => 'desc',
        );
        $leaders = new WP_Query( $args );
        ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Posts from current week using date picker value’ is closed to new replies.