function update_field($field_key, $value, $post_id = false) { // filter post_id $post_id = acf_filter_post_id($post_id); // vars $options = array('load_value' => false, 'format_value' => false); $field = get_field_object($field_key, $post_id, $options); if (!is_array($field)) { $field = array('type' => 'none', 'name' => $field_key); } // sub fields? They need formatted data if ($field['type'] == 'repeater') { $value = acf_convert_field_names_to_keys($value, $field); } elseif ($field['type'] == 'flexible_content') { if ($field['layouts']) { foreach ($field['layouts'] as $layout) { $value = acf_convert_field_names_to_keys($value, $layout); } } } // save do_action('acf/update_value', $value, $post_id, $field); return true; }
function live_edit($fields = false, $post_id = false) { // validate fields if (!$fields) { return false; } // filter post_id $post_id = acf_filter_post_id($post_id); // turn array into string if (is_array($fields)) { $fields = implode(',', $fields); } // remove any white spaces from $fields $fields = str_replace(' ', '', $fields); // build atts echo 'data-live-edit-id="' . $post_id . '-' . str_replace(',', '-', $fields) . '" data-live-edit-fields="' . $fields . '" data-live-edit-post_id="' . $post_id . '"'; }