Support » Fixing WordPress » Display post based on day in week

  • McGee

    (@maniche)


    Hello,

    I’m planning to create 7 posts and call one of them every day in week.
    Each post will be related to specific day.
    I know how custom query works but i dont know how to do this:/

    Can someone plase provide me with code.

    thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • vjpo

    (@vjpo)

    Hi, McGee, if you mean that you want to show, say, one “Monday” post every Monday, that pretty easy with custom post meta and date() function, that can return current weekday. date('l') returns Sunday, date('D') returns Sun, for your taste.
    http://codex.wordpress.org/Formatting_Date_and_Time

    E.g. if you add post meta with key ‘weekday’ and value ‘Sunday’, then you can query where do you want post with this meta.

    $currentday = date('l');
    $query = new WP_Query( array( 'meta_key' => 'weekday', 'meta_value' => $currentday ) );

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

    Thread Starter McGee

    (@maniche)

    Hi vjpo,

    “Hi, McGee, if you mean that you want to show, say, one “Monday” post every Monday, “

    Thats excatly what i want..monday post every monday, repeatedly..

    been working whole day, im burned atm so i did not fully understood your post..
    as i understood, 1 is for sunday, 2 for monday etc etc..
    can you provide me with custom query that has all 7 days in week asociated with specific post name..?

    thanks for your feedback!

    vjpo

    (@vjpo)

    date('l') there is lowercase L, not 1. This function automatically returns day of week. As Sunday, Monday etc.
    So you can assign specific custom fields to posts those you want to rotate.
    Like on this image “Name” can be “weekday” (same for all 7 posts) and value “Thursday” etc.
    Read more about custom fields http://codex.wordpress.org/Custom_Fields

    Then you can automatically query posts with current day name custom field. I can’t provide more detailed code, because you didn’t mention the details.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display post based on day in week’ is closed to new replies.