Home › Forums › Backend Issues (wp-admin) › Update ACF Field on daily basis › Reply To: Update ACF Field on daily basis
Ah! Add this to the top of the file (after the <?php):
# Our include
require_once('../../../wp-load.php');
I think you can uncomment the other bits:
<?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();
$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;
This assumes you’ve added the file (cron.php) into your theme dir. If you’ve added it within a directory in your theme (like includes), you need to amend the path to wp-load.php
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.