Last active
October 27, 2020 20:44
-
-
Save tdrayson/29c18cb5d127c1cae07997e343be3790 to your computer and use it in GitHub Desktop.
Update an ACF Field based on if the date is in the past.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tct_set_new_date() { | |
$posts = get_posts( array('post_type' => 'session', 'posts_per_page' => - 1) ); | |
$current_date = date( "Y-m-d h:i" ); | |
foreach($posts as $post) { | |
$old_date = get_field( 'date', $post->ID ); | |
if($old_date < $current_date) { | |
$new_date = date( 'Y-m-d h:i', strtotime( '+1 week', strtotime( $old_date ) ) ); | |
update_field( 'date', $new_date, $post->ID ); | |
} | |
} | |
} | |
if(!get_transient( 'tct_date' )) { | |
tct_set_new_date(); | |
set_transient( 'tct_date', 1, 60 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment