Home › Forums › Backend Issues (wp-admin) › Calculate PHP date_diff and save to ACF Field during post creation › Reply To: Calculate PHP date_diff and save to ACF Field during post creation
Unfortunately the value seems to not update everyday. Does anyone if I should upgrade the code or add some cron job or something?
$new_post = array(
'post_title' => "Order {$order_id}", // Definieer titel van de post
'post_date' => date('Y-m-d H:i:s'), // Voeg publicatiedatum toe
'post_author' => $user_ID, // Definieer de klant als auteur
'post_type' => 'groeiproces', // Definieer CPT
'post_status' => 'publish', // Publiceer post
);
$post_id = wp_insert_post($new_post);
$now = time();
$date_created = $order->get_date_created();
$dt = new DateTime($date_created);
$date = $dt->format('Y-m-d');
$your_date = strtotime($date);
$datediff = $now - $your_date;
$diff = round($datediff / (60 * 60 * 24));
update_post_meta( $post_id, 'datum', $diff );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.