• Hi,

    I have a query issue that I can’t solve. I made a really profound research without any result. So:
    I’m developing a WordPress site – the owner would like to structure her posts by day: a certain kind of post thematics on monday, another on tuesday, and so on until friday.
    I got an idea to structure the blog posts page so that it has 5 boxes, each of them showing the latest post for a certain day. Thus the first box should display the latest post published on a monday, the second the latest post published on a tuesday and so on and on.

    The problem is that I can’t find a custom query that can solve this. All the queries are related to ‘current year’, ‘current month’, a given year etc., but there seems to be nothing concerning queries by publication day.

    I would be grateful for any help to solve this issue.

    Thanks, cheers:
    Lunule

Viewing 3 replies - 1 through 3 (of 3 total)
  • This will get the most recent post for Thursday (day 5):

    <?php
       $sql = "SELECT *,dayname(post_date) as dayname
    FROM $wpdb->posts
    WHERE dayofweek(post_date) = 5
    AND post_type ='post'
    AND post_status='publish'
    LIMIT 0,1";
       $my_posts = $wpdb->get_results($sql);
    
       if ($my_posts) {
         foreach ($my_posts as $post) {
           setup_postdata($post);?>
           <p><?php the_title(); ?>&nbsp;&nbsp;<?php echo "$post->dayname ";the_time('F jS, Y',$post->post_date); ?></p>
         <?php }
       }
    ?>
    Thread Starter Gabor Lippert

    (@lunule)

    Hey vtxyzzy!

    You have a really bizarre nick name, but anyway: you’re a geeeenius!
    The code works fine!

    Thanks for your help!
    lunule

    Well, the first computer adventure game had a magic word, xyzzy, that would transport you to another location. I ride a Honda VTX motorcycle and it is my magic transporter, so vtxyzzy!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Query posts published on a certain day of the week’ is closed to new replies.