WordPress.org

Support

Support » How-To and Troubleshooting » Query Post by day

Query Post by day

  • Dear all,

    I want to query post future (scheduled) posts by day
    example:
    Sunday
    Item 1 | Item 2 | Item 3
    Monday
    Item 1 | Item 2 | Item 3
    Tuesday
    Item 1 | Item 2 | Item 3
    Wednesday
    Item 1 | Item 2 | Item 3
    Thursday
    Item 1 | Item 2 | Item 3

    How can I do this correctly?

    I got something like this for wednesday, but it isnt dynamic and working, I want to do this automatic:

    $my_query = new WP_Query( array(
    'post_type' => array('post','shows','movies'),
    'paged' => $paged,
    'day'=> array(6, 13),
    'post_status' => 'future',
    'posts_per_page'=>8 ));

    Greetings
    Stefan

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can find the next instance of a day of the week by using strtotime(), for example: date('j', strtotime('next tuesday'));
    You can replace tuesday, with whatever day you want and then use that in your query.

    From here: http://stackoverflow.com/questions/1188728/get-the-date-of-next-monday-tuesday-etc

    I think it works!

    Thanks!

    What I used is :

    <?
        $sunday 	= date('j', strtotime('next sunday'));
        $monday 	= date('j', strtotime('next monday'));
        $tuesday	= date('j', strtotime('next tuesday'));
        $wednesday 	= date('j', strtotime('next wednesday'));
        $thursday 	= date('j', strtotime('next thursday'));
    ?>
    <?php
    $my_query = new WP_Query( array(
    'post_type' => array('post','shows','movies'),
    'paged' => $paged,
    'day'=>$sunday,
    'post_status' => 'future',
    'posts_per_page'=>8 ));
    
    if ($my_query->have_posts()) {
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query Post by day’ is closed to new replies.