Support

Account

Home Forums General Issues Update_field not working

Solved

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

  • What version of ACF are you using?

  • 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] );
    				}
    			}
    
  • That did the trick. Thanks so much John!

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

You must be logged in to reply to this topic.