I am working on a Wordpress site that shows "On this day" posts. So for example when I load the site it shows all posts that were published on the current day from any year. So for example when I load the page today it will show every post from 14th March regardless of year.
I have added the function "historical_posts_list" (See below) to Functions.php and this seems to work as expected. When I load the site it only shows posts from todays date for every year, Great !
Where I am stuck and looking for assistance is how I could add a date picker of some sort so that the user could then choose say January 1st and the page would update to show posts from the new date.
Hope that makes sense.
Any help appreciated. This is my first dive into Wordpress.
I have added the function "historical_posts_list" (See below) to Functions.php and this seems to work as expected. When I load the site it only shows posts from todays date for every year, Great !
Where I am stuck and looking for assistance is how I could add a date picker of some sort so that the user could then choose say January 1st and the page would update to show posts from the new date.
Hope that makes sense.
Any help appreciated. This is my first dive into Wordpress.
Code:
function historical_posts_list( $query ){
if( $query->is_home() && $query->is_main_query() ){
$date_query = array(
array(
'month' => date( 'n', current_time( 'timestamp' ) ),
'day' => date( 'j', current_time( 'timestamp' ) )
)
);
$query->set( 'date_query', $date_query );
}
}
add_action( 'pre_get_posts', 'historical_posts_list' );