最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Update post meta date always store 1970-01-07

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

With 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'));
发布评论

评论列表(0)

  1. 暂无评论