Created
November 11, 2016 21:45
-
-
Save lukecav/39e0407e082aa5cd3cdbf90b2e9e036b to your computer and use it in GitHub Desktop.
Expire posts to draft using a datepicker field in ACF
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
// Expire events | |
if ($expireTransient = get_transient($post->ID) === false) { | |
set_transient($post->ID, 'set for 1 minutes', 1 * MINUTE_IN_SECONDS ); | |
$today = date('Y-m-d H:i:s', current_time('timestamp', 0)); | |
$args = array( | |
'post_type' => 'events', | |
'posts_per_page' => 200, | |
'post_status' => 'publish', | |
'meta_query' => array( | |
array( | |
'key' => 'end_date_time', | |
'value' => $today, | |
'compare' => '<=' | |
) | |
) | |
); | |
$posts = get_posts($args); | |
foreach( $posts as $post ) { | |
if(get_field('end_date_time', $post->ID)) { | |
$postdata = array( | |
'ID' => $post->ID, | |
'post_status' => 'draft' | |
); | |
wp_update_post($postdata); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this code, I use it often. Most of my sites I host on Siteground and have no issue, but for some reason this will not work on AWS Lightsail or EC2. Would you have any advice or idea why that might be?