GrayofD4
9/21/2017 - 6:34 PM

Redirect to post of the day

Redirect to post of the day

<?php
function show_post_of_the_day( $query ) {

	if ( $query->is_home() && ! is_admin() && $query->is_main_query() ) {

		$today = getdate();

		$args = array(
			'post_type' => 'post',
			'date_query' => array(
				array(
				#	'year'  => 2012,
					'month' => $today['mon'],
					'day'   => $today['mday'],
				),
			),
		);
		$new_query = new WP_Query( $args );

		$permalink = home_url('/');
		while( $new_query->have_posts() ) {
			$new_query->the_post();

			$permalink = get_permalink();
		} wp_reset_postdata();

		#echo $permalink;
		header( 'Location: '. $permalink );
	}

} add_action( 'pre_get_posts', 'show_post_of_the_day' );