Home › Forums › General Issues › Auto Update Field based on ACF Date Picker field › Reply To: Auto Update Field based on ACF Date Picker field
Ok. Problem solved.
I changed this:
if (($expiredate < $today) && ($expiredate != "")) { // if date is less than today, but also not empty to accomodate the coupons that don't expire
$postdata = array(
'ID' => $p->ID,
'post_status' => 'draft'
);
wp_update_post($postdata);
}
To that:
$expiredate = get_field('coupon_valid_till', $p->ID, false, false); // get the raw date from the db. false, false will convert to Ymd while allowing you to use any date format output choice on the field itself
if (($expiredate < $today) && ($expiredate != "")) {
$field_key = "field_634c04868ed81";
$value = "1";
update_field($field_key, $value, $post->ID);
}
} // end while have_posts
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.