WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to show post of current week (5 posts)

  1. gnurf
    Member
    Posted 2 years ago #

    I hope someone can help me in the right direction with this one:

    Say you have some contributors writing posts about weekly happenings. One write about Monday happenings and another about Tuesday happenings and so on. These post are written a week or so in advance.

    How can I list all posts for a preferred week, for example current week and next week?

    All suggestions are welcome!

    -Paul

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    http://codex.wordpress.org/Class_Reference/WP_Query
    http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters

    example:

    $this_week_query = new WP_Query(array('posts_per_page' => -1, 'w' => date('W')));

    $next_week_query = new WP_Query( array('posts_per_page' => -1, 'w' => (date('W')+1)) );

    (not tested)

    if it is the only query on the page, you could also try to work with query_posts() using the same parameters;
    http://codex.wordpress.org/Function_Reference/query_posts

  3. gnurf
    Member
    Posted 2 years ago #

    Should the post be published as scheduled for upcoming weeks, or is there any other ways of adding a "time stamp" if you publish immediately?

  4. Nikki Blight
    Member
    Posted 2 years ago #

    If you schedule a post for an upcoming date, it won't be visible on the site until that date is reached. So if your intention is to have a list of articles about upcoming events that people can read ahead of time, you'll need to publish them immediately.

    If you need to add an additional timestamp, I'd just put it in a custom field and add that field to your template. Or alternatively just use Taxonomy and categorize the posts by day of the week.

  5. gnurf
    Member
    Posted 2 years ago #

    Excellent! Got it working. By adding post_status set to publish and future I am also able to list scheduled posts:

    $my_query = new WP_Query(array('post_status' => 'publish,future', 'posts_per_page' => -1, 'w' => date('W'),'order'=>ASC));

Topic Closed

This topic has been closed to new replies.

About this Topic