Using Wp User query the metafield part is working but still im trying to make the time function working. Seems the Math is not taken in account.
I am using the following:
$now = time(); // right now
$postdate = strtotime(get_the_date()); // the post date
$datediff = $now - $postdate; // math
$daysdiff = floor($datediff / (60 * 60 * 24)); // rounding down
if($daysdiff >= 4 ){ // if the post is older than 4 days
comment_form();
}
The comment box is displaying no matter what although the post is not older than 4 days.
Also I just realized that the post is in “Fixing WordPress” instead of “Developing with wordpress” … Maybe you can move it to?
Thank you.
]]>I did the math using echo on variables. $now = time();
was not giving anything.
So i used $now = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) );
to get current time. I also did some changed in the code. Im sharing the following working code:
$now = date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) ); // right now
$ts1 = strtotime($now);
$ts2 = strtotime(get_the_date('Y-m-d H:i:s'));
$datediff = $ts1 - $ts2;
$daydiff = floor($datediff / 86400);
if($daydiff >= 4 ){ // if the post is older than 4 days
comment_form();
} else {
echo "Post is not old enuf";
}
If anyone want help on how to setup restrict content with user meta field please feel free to ask.
Cheers
]]>