Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.