Last active
December 22, 2016 12:31
-
-
Save badabingbreda/cc2c89005035ef02a47a7307221f736d to your computer and use it in GitHub Desktop.
ACF Template Builder - changing field-type output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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