Home › Forums › Backend Issues (wp-admin) › Update ACF Field on daily basis › Reply To: Update ACF Field on daily basis
Also add some debugging in, check your script outputs what it should:
<?php
# Our include
require_once('../../../wp-load.php');
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => -1,
'post_type' => 'groeiprocessen',
'fields' => 'ids', //not sure what to add here
'post_status' => array('publish'),
'paged' => $paged
);
$wp_query = new WP_Query($args);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post();
$post_id = get_the_ID();
echo '<p>Post ID: '.$post_id.'</p>';
$datetime1 = new DateTime();
echo '<p>Date time 1: '.$datetime1.'</p>';
$datetime2 = get_field( "datum" );
echo '<p>Date time 2: '.$datetime2.'</p>';
$difference = $datetime1->diff($datetime2);
echo '<p>Difference: '.$difference.'</p>';
$verschil = "difference " . $difference->days . " days ";
echo '<p>Difference: '.$verschil.'</p>';
update_post_meta( $post_id, 'datum2', $verschil );
endwhile;
endif;
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!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.