Support

Account

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();