您正在使用get_the_date() 错误的该函数以给定格式获取帖子的日期,第二个参数是帖子获取日期的帖子ID。不是时候了。
最简单的方法就是使用时间戳。因此,您可以使用DAY_IN_SECONDS WordPress提供的常量:
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();
}
}
关键在于:
current_time( \'U\' ) <= get_the_date( \'U\' ) + ( 3 * DAY_IN_SECONDS )
这应该可以避免不同时区之间的问题
current_time() 和
strtotime().
PS:我还更改了你的倍数in_category() 使用数组调用到单个调用中。