Skip to content

Instantly share code, notes, and snippets.

@badabingbreda
Last active December 22, 2016 12:31
Show Gist options
  • Save badabingbreda/cc2c89005035ef02a47a7307221f736d to your computer and use it in GitHub Desktop.
Save badabingbreda/cc2c89005035ef02a47a7307221f736d to your computer and use it in GitHub Desktop.
ACF Template Builder - changing field-type output
remove_filter( 'bbacf/helpers/get_acf_field/type=checkbox' , 'bbacf_helpers::shortcode_acf_return_checkbox' ,10 );
add_filter( 'bbacf/helpers/get_acf_field/type=checkbox' , 'return_custom_acf_checkbox' , 11, 5 );
function return_custom_acf_checkbox ( $string , $field_object , $value , $atts = null , $postid = null ) {
// get the correct fieldname for version 4 or 5 of acf
$get_fo = bbacf_helpers::$fr[ bbacf_acf_version() ];
if ( $field_object[ 'type' ] == 'text' ) return $string . $value ;
// determine return-value of checkbox
switch ($field_object[ $get_fo ] ) {
case 'array':
$selected_values = '';
foreach ($field_object[ 'value' ] as $choice ) {
if ( in_array( $choice , $value ) ) {
$selected_values .= '<div style="clear:both;"><div style="background-color:' . $choice[ 'label' ] . ';width:24px;height:24px;float:left;margin-right:5px;border:1px solid #f1f1f1;"></div>' . $choice[ 'label' ] . '</div>';
};
}
return $string . $selected_values;
break;
default:
return $string . join( $value, ', ' );
break;
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment