Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Last active October 27, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdrayson/29c18cb5d127c1cae07997e343be3790 to your computer and use it in GitHub Desktop.
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.
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