Home Forums ACF PRO auto fill ACF input using iTunes Search API Value Reply To: auto fill ACF input using iTunes Search API Value

  • I am on a roll answering everyone’s questions today so here we go with another…

    This function will run every time a field is updated to check if your field needs to be checked. If your field is found it checks the value to see if it has changed since last update. If it has it will run your api call and update the other fields necessary as declared by you.

    function my_acf_update_value( $value, $post_id, $field  ) {
        // only do it to certain custom field
        if( $field['name'] == 'custom_field_name' ) {
            // get the old (saved) value
            $old_value = get_field('custom_field_name', $post_id);
            // get the new (posted) value
            $new_value = $_POST['acf']['field_1234567890abc'];
            // check if the old value is the same as the new value
            if( $old_value != $new_value ) {
    			// do your api call functions and return you size and what not
    			update_field('sizeField',$sizeValue, $post_id);
    	// don't forget to return to be saved in the database
        return $value;
    // acf/update_value - filter for every field
    add_filter('acf/update_value', 'my_acf_update_value', 10, 3);