Support

Account

Home Forums Backend Issues (wp-admin) update Datepicker-Field issue

Solving

update Datepicker-Field issue

  • Hi
    When updating a field from the type Datepicker, then it gives me an an empty field in that post in the backend.
    When using the get_date() functen to check the value, it is set to the todays date.

    Is that a common issiue or is there something to be aware when updating Datepicker fields ??

  • Hi @phoenix-systems

    Thank you for the question.

    This is certainly not a common issue, it may be possible that there is a plugin/ theme conflict that is interfering with the saving of values in the date picker field.

    I would recommend you try to investigate by deactivating all other installed plugins and switching to one of the stock WP themes to check if the issue will be replicated.

  • @phoenix-systems I have kind of the same problem and I think I found the problem, and the solution.

    I realized that updating a DatePicker field, requires you to pass the date with the ‘Ymd’ format (PHP) no matter what format you are using (they really should add it to the documentation).

    my code: (dob = date of birth…)

    
    $dob_str = '23/11/1984';
    $date = DateTime::createFromFormat('d/m/Y', $dob_str);
    $date = $date->format('Ymd');
    
    update_field('date_of_birth', $date, $post_id);
    

    Also worth mentioning is that if you are trying to update a field with the same value (from the database) the function returns false, but that’s WP behaviour if I’m not mistaken.

    Hope it helps you.
    Daniel

  • You sir, are my hero. I wasted about an hour trying to figure out what I was doing wrong.

    And yes, they should REALLY add it to the docs.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘update Datepicker-Field issue’ is closed to new replies.