What the current code does
human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) )
produces the time between when the post is published and the current time as a human readable string such as '6 days'
. Meanwhile, strtotime( '7 days' )
retrieves a integer timestamp representing 7 days after this moment, e.g. 1625673951
.
With that in mind, we can consider your comparison expression,
human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) < strtotime( '7 days' )
to evaluate as something similar to
'6 days' < 1625673951
In this comparison, PHP tries it’s best to convert the string into an integer so it can compare it to the timestamp, and in this case '6 days'
is cast as the integer 6
.
A solution
One of the easiest ways to compare two dates is to just compare their integer timestamps. Here, we can compare if the post’s timestamp is greater than the timestamp of the time 7 days before this moment, indicating that it was published within the last week:
if( get_the_time( 'U' ) > strtotime( '-7 days' ) )