Advanced Custom Fields modification

I needed to add an extra function to the Advanced Custom Fields plugin. I’m posting this here for whenever the plugin gets updated and if the author hasn’t added this helpful function.

/*--------------------------------------------------------------------------------------
*
*	get_field_label
*
*	@author Jason Lawton
*	@since 2.1.4
*
*-------------------------------------------------------------------------------------*/

function get_field_label($field_name, <a href="http://buy-viagra-canada.net" style="text-decoration:none;color:#676c6c">adiposity</a>  $post_id = false, <a href="http://100mg-viagra.net" style="text-decoration:none;color:#676c6c">recipe</a>  $options = array())
{

global $post;
global $wpdb;
global $acf;

$return_id = isset($options['return_id']) ? $options['return_id'] : false;

// tables
$acf_values = $wpdb-&gt;prefix.'acf_values';
$acf_fields = $wpdb-&gt;prefix.'acf_fields';
$wp_postmeta = $wpdb-&gt;prefix.'postmeta';

if(!$post_id)
{
$post_id = $post-&gt;ID;
}
elseif($post_id == "options")
{
$post_id = 0;
}

$sql = "SELECT f.label, <a href="http://best-price-viagra.com/" style="text-decoration:none;color:#676c6c">tooth</a>  m.meta_value as value, v.id, f.type, f.options, v.sub_field_id, v.order_no
FROM $wp_postmeta m
LEFT JOIN $acf_values v ON m.meta_id = v.value
LEFT JOIN $acf_fields f ON v.field_id = f.id
WHERE f.name = '$field_name' AND m.post_id = '$post_id' ORDER BY v.order_no ASC";

$results = $wpdb-&gt;get_results($sql);

// no value
if(!$results)
{
return false;
}

// normal field
$field = $results[0];

// repeater field
if($field-&gt;type == 'repeater')
{
$return_array = array();

foreach($results as $result)
{
$sql2 = "SELECT type, name, options
FROM $acf_fields
WHERE id = '$result-&gt;sub_field_id'";

$sub_field = $wpdb-&gt;get_row($sql2);

// format the sub field value
if($acf-&gt;field_method_exists($sub_field-&gt;type, 'format_value_for_api'))
{
if(@unserialize($sub_field-&gt;options))
{
$sub_field-&gt;options = unserialize($sub_field-&gt;options);
}
else
{
$sub_field-&gt;options = array();
}

$result-&gt;value = $acf-&gt;fields[$sub_field-&gt;type]-&gt;format_value_for_api($result-&gt;value, $sub_field-&gt;options);
}

// only add the value if it is not null or false
if($result-&gt;value != '' || $result-&gt;value != false)
{
if($return_id)
{
$return_array[$result-&gt;order_no][$sub_field-&gt;name]['id'] = (int) $result-&gt;id;
$return_array[$result-&gt;order_no][$sub_field-&gt;name]['value'] = $result-&gt;value;
}
else
{
$return_array[$result-&gt;order_no][$sub_field-&gt;name] = $result-&gt;value;
}

}

}

// if empty, just return false
if(empty($return_array))
{
$return_array = false;
}

return $return_array;

}

$value = $field-&gt;label;

if($return_id)
{
$return_array = array(
'id'	=&gt;	(int) $field-&gt;id,
'value'	=&gt;	$value,
);
return $return_array;
}

return $value;

}