false,
'format_value' => false
);
$field = get_field_object( $field_key, $post_id, $options);
// 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;
}
/*
* delete_field()
*
* This function will remove a value from the database
*
* @type function
* @since 3.1.9
* @date 29/01/13
*
* @param mixed $field_name: the name of the field - 'sub_heading'
* @param mixed $post_id: the post_id of which the value is saved against
*
* @return N/A
*/
function delete_field( $field_name, $post_id )
{
do_action('acf/delete_value', $post_id, $field_name );
}
/*
* create_field()
*
* This function will creat the HTML for a field
*
* @type function
* @since 4.0.0
* @date 17/03/13
*
* @param array $field - an array containing all the field attributes
*
* @return N/A
*/
function create_field( $field )
{
do_action('acf/create_field', $field );
}
/*
* acf_convert_field_names_to_keys()
*
* Helper for the update_field function
*
* @type function
* @since 4.0.0
* @date 17/03/13
*
* @param array $value: the value returned via get_field
* @param array $field: the field or layout to find sub fields from
*
* @return N/A
*/
function acf_convert_field_names_to_keys( $value, $field )
{
// only if $field has sub fields
if( !isset($field['sub_fields']) )
{
return $value;
}
// define sub field keys
$sub_fields = array();
if( $field['sub_fields'] )
{
foreach( $field['sub_fields'] as $sub_field )
{
$sub_fields[ $sub_field['name'] ] = $sub_field;
}
}
// loop through the values and format the array to use sub field keys
if( is_array($value) )
{
foreach( $value as $row_i => $row)
{
if( $row )
{
foreach( $row as $sub_field_name => $sub_field_value )
{
// sub field must exist!
if( !isset($sub_fields[ $sub_field_name ]) )
{
continue;
}
// vars
$sub_field = $sub_fields[ $sub_field_name ];
$sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field );
// set new value
$value[$row_i][ $sub_field['key'] ] = $sub_field_value;
// unset old value
unset( $value[$row_i][$sub_field_name] );
}
// foreach( $row as $sub_field_name => $sub_field_value )
}
// if( $row )
}
// foreach( $value as $row_i => $row)
}
// if( $value )
return $value;
}
/*
* Depreceated Functions
*
* @description:
* @created: 23/07/12
*/
/*--------------------------------------------------------------------------------------
*
* reset_the_repeater_field
*
* @author Elliot Condon
* @depreciated: 3.3.4 - now use has_sub_field
* @since 1.0.3
*
*-------------------------------------------------------------------------------------*/
function reset_the_repeater_field()
{
// do nothing
}
/*--------------------------------------------------------------------------------------
*
* the_repeater_field
*
* @author Elliot Condon
* @depreciated: 3.3.4 - now use has_sub_field
* @since 1.0.3
*
*-------------------------------------------------------------------------------------*/
function the_repeater_field($field_name, $post_id = false)
{
return has_sub_field($field_name, $post_id);
}
/*--------------------------------------------------------------------------------------
*
* the_flexible_field
*
* @author Elliot Condon
* @depreciated: 3.3.4 - now use has_sub_field
* @since 3.?.?
*
*-------------------------------------------------------------------------------------*/
function the_flexible_field($field_name, $post_id = false)
{
return has_sub_field($field_name, $post_id);
}
/*
* acf_filter_post_id()
*
* This is a deprecated function which is now run through a filter
*
* @type function
* @since 3.6
* @date 29/01/13
*
* @param mixed $post_id
*
* @return mixed $post_id
*/
function acf_filter_post_id( $post_id )
{
return apply_filters('acf/get_post_id', $post_id );
}
?>