You’re using get_the_date()
wrong. That function gets the date of the post in a given format, and the 2nd argument is the Post ID for the post to get the date for. Not a time.
The simplest way to do this would be to just use timestamps. So you can just get the post date timestamp and add 3 days using the DAY_IN_SECONDS
constant that WordPress provides:
if (
! is_user_logged_in()
&& in_category( array( 'test2', 'test1' ) )
&& current_time( 'U' ) <= get_the_date( 'U' ) + ( 3 * DAY_IN_SECONDS )
) {
echo 'Sorry';
} else {
the_content();
}
}
The key bit being:
current_time( 'U' ) <= get_the_date( 'U' ) + ( 3 * DAY_IN_SECONDS )
This should avoid issues with differences in timezones between current_time()
and strtotime()
.
PS: I also changed your multiple in_category()
calls into a single call with an array.