WordPress.org

Ready to get started?Download WordPress

Forums

Query Post by day (3 posts)

  1. Steekvlam
    Member
    Posted 1 year ago #

    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

  2. Andrew Bartel
    Member
    Posted 1 year ago #

    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

  3. Steekvlam
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic