Home › Forums › ACF PRO › Cron Jobs & Date Checking › Reply To: Cron Jobs & Date Checking
You need to have a loop in order to get and update fields.
Your query should already be returning the posts that you want
to update and you shouldn’t need to test them again.
// Scheduled Action Hook
function check_job_end_date( ) {
// Variables
$today = date('Ymd');
// Query
$listings = new WP_Query(
array(
'post_type' => 'job_listings',
'meta_query' => array(
'key' => 'job_listing_closing_date',
'value' => $today,
'compare' => '<'
)
)
);
global $post;
if ($listings->have_posts()) {
while ($listings->have_post()) {
$listings->the_post();
update_field('job_listing_job_status', 'Closed');
}
wp_reset_postdata();
}
}
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.