Home › Forums › ACF PRO › Cron Jobs & Date Checking › Reply To: Cron Jobs & Date Checking
Hello,
How did you make that work? I used your code for a similar function but i cannot get it to work.
My case is that we have 2 Post Categories. 1. Upcoming Events and 2.Passed Events.
We create a post with ACF event_end_date which is an ACF Date picker. What we need to do is have a cron job that checks if the event_end_date has passed so it updates the Post Category from Upcoming Events to Passed Events. I just cant make it work. Here is the code if you guys got any input i would be thankful!
/* Scheduled Action Hook */
function check_event_end_date() {
global $post;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => array(33), /*Upcoming Events Category ID*/
'posts_per_page' => -1,
);
$listings = get_posts( $args );
foreach($listings as $post) : setup_postdata($post);
$today = date( 'Ymd' );
$expire = get_field( 'event_end_date', false, false );
if ( $expire > $today ) :
$post_categories="36"; /*Passed Events Category ID*/
$append=false;
wp_set_post_categories( $post_ID, $post_categories, $append );
endif;
endforeach;
}
// Schedule Cron Job Event
if ( ! wp_next_scheduled( 'event_end_date_cron_job' ) ) {
wp_schedule_event( date( 'Ymd' ), 'daily', 'event_end_date_cron_job' );
}
add_action( 'event_end_date_cron_job', 'check_event_end_date' );
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!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.