Support

Account

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 );