Support

Account

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!