I am creating a website about 'This Day in History' where I show daily events etc. all based on a particular date. Each post has to be re-posted every year, and a specific date so that everyday users see information relevant to today's date.
So if I have 365 posts, one for each day, each post must be the published post for that specific date. In other words, posts kind of rotate every day throughout the year. So every day a new post is published, the very post that matches that date... I hope I make my self clear :-)
Is there a way I can control how the posts are (re)-scheduled, so that they continue to get posted each year on that specific date?
Thanks
/Anders
I am creating a website about 'This Day in History' where I show daily events etc. all based on a particular date. Each post has to be re-posted every year, and a specific date so that everyday users see information relevant to today's date.
So if I have 365 posts, one for each day, each post must be the published post for that specific date. In other words, posts kind of rotate every day throughout the year. So every day a new post is published, the very post that matches that date... I hope I make my self clear :-)
Is there a way I can control how the posts are (re)-scheduled, so that they continue to get posted each year on that specific date?
Thanks
/Anders
Rather than re-post the posts, we can create a custom query for the current day's post regardless of year. We use current_time
to get the current day and month according to the site's timezone settings, then we create a new query containing date parameters for month and day. We don't specify a year, so it'll return anything posted on this day from any year.
$day = current_time( 'j' );
$month = current_time( 'n' );
$args = array(
'date_query' => array(
array(
'month' => $month,
'day' => $day,
),
),
);
$today = new WP_Query( $args );
if ( $today->have_posts() ) {
while ( $today->have_posts() ) {
$today->the_post();
// output the post
the_title();
}
wp_reset_postdata();
}