Home › Forums › Backend Issues (wp-admin) › Update ACF Field on daily basis › Reply To: Update ACF Field on daily basis
Oke, so to be sure.
I added an extra line of code, which saves the publication date in an ACF field.
$datetime1 = new DateTime();
$date_created = $order->get_date_created();
$datetime2 = new DateTime($date_created);
$difference = $datetime1->diff($datetime2);
$verschil = "difference " . $difference->days . " days ";
update_post_meta( $post_id, 'datum2', $verschil );
update_post_meta( $post_id, 'datum', $datetime2 );
So the next step is to create a file, which I save in my WordPress directory. The file should be like you showed:
<?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();
$datetime1 = new DateTime();
$datetime2 = get_field( "datum" );
$difference = $datetime1->diff($datetime2);
$verschil = "difference " . $difference->days . " days ";
update_post_meta( $post_id, 'datum2', $verschil );
endwhile;
endif;
The last step should be to trigger the URL with the Cron Job.
Is that correct? Thanks for your help!
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 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 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.