Let's say I have this URL: www.mywebsite.com/myCPT/post, here I want to check if 3 days has passed since the post was created to redirect to www.mywebsite.com/myCPT/post/stats.
In this 3 days time frame the user should not be able to access www.mywebsite.com/myCPT/post/stats.
But this needs to be dynamic, everytime a post is created to check for it's URL and add a 3 days time till this URL will be accessible www.mywebsite.com/myCPT/post/stats
For example I will have post1, post2, post3 and so on and everytime the post will be created to add a 3 days time frame till the "/post/stats" will be available.
I've did some research and I found this:
header('Refresh: 10; URL=http://yoursite.com/page.php');
Found also an wordpress function for redirection : wp_redirect( $location, $status );
Another function for getting the date when the post was created :
<?php echo get_the_date(); ?>
and <?php echo get_the_time(); ?>
Found a snippet which might be helpful :
if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( 30 * 24 * 60 * 60 ) ) {
// DO SOMETHING
}
return $posts;
}
Later edit:
The "/stats"
is built like this:
function wpa121567_rewrite_endpoints(){
add_rewrite_endpoint( 'stats', EP_PERMALINK );
}
add_action( 'init', 'wpa121567_rewrite_endpoints' );
There are also some plugin where you can set custom redirects but no one offers me the functionality to add a time frame.
Any suggestions on how can I achieve this ? Thank you !