To redirect after 3 days gone after publication, hook into template_redirect
, check if is a singular cpt view, check the date and compare to current time and redirect if needed.
In the 3 days time frame, check if stats is is the query vars and if so redirect to post page.
add_action('template_redirect', 'check_the_date_for_stats');
function check_the_date_for_stats() {
if ( is_singular('myCPT ') ) { // adjust myCPT with your real cpt name
$pl = get_permalink( get_queried_object() ); // permalink
$is_stats = array_key_exists( 'stats', $GLOBALS['wp_query']->query ); // is stats?
$is_cm = array_key_exists( 'comments', $GLOBALS['wp_query']->query ); // is comments?
$ts = mysql2date('Ymd', get_queried_object()->post_date_gmt ); // post day
$gone = ($ts + 3) < gmdate('Ymd'); // more than 3 days gone?
if ( $gone && ( ! $is_stats && ! $is_cm ) ) {
// more than 3 days gone and not is stats => redirect to stats
wp_redirect( trailingslashit($pl) . '/stats' );
exit();
} elseif( ! $gone && ( $is_stats || $is_cm ) ) {
// we are in 3 days frame and trying to access to stats => redirect to post
wp_redirect( $pl );
exit();
}
}
}