• Does anyone have any thoughts on how I could write a query to fetch a new random post every day – so Monday would have a random post, then Tuesday would have a different random post, etc.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Easy enough to display a random post.

    Difficult to guarantee that Tuesday’s post would not be the same as Monday’s post. You’d have to store the ID of each day’s random post. Does Wednesday’s post have to be random and not be Tuesday or Monday’s post.

    Can next Monday by chance have the same post as this Monday?

    Thread Starter Darfuria

    (@darfuria)

    Wednesday’s could be different to Monday’s, but Tuesday’s would have to be different to Monday’s.

    This Monday and next Monday could be the same – as long as they were randomly the same, rather than in a pattern meaning that they were the same every Monday.

    I looked for a plugin that might do that but didn’t find much. Since the nature of random means that the same post could be randomly selected on Monday and Tuesday, you will have to find a plugin (or write code) that will not only randomly select a post, but also record that post ID and show it for the whole day (as opposed to showing each visitor just a random post). Then when selecting the post for the next day, exclude the post from the previous day in the random selection.

    I’m not sure if you’re still looking for this. But, you might use the MOD function.

    Something like this. This code select pages that are children of a different page. You would use different selection code and also orderby=rand.

    $daynum = date("z");
    $openings = get_posts('post_type=page&post_parent=125&numberposts=-1&order=ASC&orderby=menu_order');
    $today_post = $openings[ $daynum % count($openings)   ];

    $today_post would be different each day. If you’re adding posts daily, though, things get more complicated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Random Daily Post’ is closed to new replies.