Home › Forums › General Issues › Update_field not working
Hey everyone,
I’m struggling with creating a plugin that grabs the exif data of a photo and saves it to a custom field.
If I uncomment and use update_post_meta, that works, saving a value like ’29 Jan, 2016′. My custom field ‘field_576d9e9337b26’ however never saves any value. Can anyone spot what I’ve done wrong?
if ( isset( $exif_data['date'] ) ) {
// example: 2016:06:19 23:04:47
$first_string = substr( $exif_data['date'], 0, 10);
$parts = explode( ":" , $first_string );
$date_shot = $parts[2] . ' ' . date( 'M', $parts[1] ) . ', ' . $parts[0];
$fieldkey = 'field_576d9e9337b26';
//update_post_meta( $post_id, 'date_shot', $date_shot );
if ( function_exists( 'update_field' ) ){
update_field( $fieldkey, $date_shot, $post_id );
if ( isset( $_POST['fields'][$fieldkey] ) )
unset($_POST['fields'][$fieldkey] );
}
}
What type of field are you trying to update? You’re adding a date, is it a date field?
Hi John,
thanks for your response. I originally had it as a date picker field, but added a new text field and changed the $fieldkey to reflect that. It still didn’t work unfortunately
Mike
ACF 5 uses the $_POST index of ‘acf’
if ( isset( $exif_data['date'] ) ) {
// example: 2016:06:19 23:04:47
$first_string = substr( $exif_data['date'], 0, 10);
$parts = explode( ":" , $first_string );
$date_shot = $parts[2] . ' ' . date( 'M', $parts[1] ) . ', ' . $parts[0];
$fieldkey = 'field_576d9e9337b26';
//update_post_meta( $post_id, 'date_shot', $date_shot );
if ( function_exists( 'update_field' ) ){
update_field( $fieldkey, $date_shot, $post_id );
if ( isset( $_POST['acf'][$fieldkey] ) )
unset($_POST['acf'][$fieldkey] );
}
}
The topic ‘Update_field not working’ is closed to new replies.
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.