I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but with this code always store 1970-01-07 as date.
$lejar_datum = get_post_meta($job_id , '_job_expires', true);
$date = date('Y-m-d',strtotime('+1 week',$lejar_datum));
update_post_meta( $job_id, '_job_expires', $date);
How can I store the current "job_expires" date + 1 week?
I want to update the post meta "job_expires" to the current "job_expires" meta data + 1 week but with this code always store 1970-01-07 as date.
$lejar_datum = get_post_meta($job_id , '_job_expires', true);
$date = date('Y-m-d',strtotime('+1 week',$lejar_datum));
update_post_meta( $job_id, '_job_expires', $date);
How can I store the current "job_expires" date + 1 week?
Share Improve this question asked Jun 15, 2019 at 10:41 gezukagezuka 175 bronze badges1 Answer
Reset to default 0With debugging enabled, you should have gotten the following message:
Notice: A non well formed numeric value encountered
This is because strtotime()
expects an integer as its second argument. You could use it like so
$date = date('Y-m-d', strtotime('+1 week', strtotime($lejar_datum)));
or if you want to use the more modern approach with DateTime
$dt = DateTime::createFromFormat('Y-m-d', $lejar_datum)->modify('+1 week');
update_post_meta($job_id, '_job_expires', $dt->format('Y-m-d'));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399489a4626033.html
评论列表(0条)