Home › Forums › ACF PRO › Select field array problem… › Reply To: Select field array problem…
I have ACF PRO version 5.8.7, and I still getting an array instead of a string from acf select fields when this is inside a flexible content. So I used designertastic
conditional code to create a function and then used it on every select field.
/**
*
* Array to string.
*
* This function is a workaround to ACF Select fields that sometimes output an array instead of a string.
*
* @param array $array Array value.
* @return string value as string.
*/
public function arr2str( $array ) {
if ( empty( $array ) ) {
return;
}
if ( is_array( $array ) ) {
$string = $array[0];
} else {
$string = $array;
}
return $string;
}
Usage
$button_style = arr2str( $button['button_style'] );
$button_style = arr2str( get_field( 'button_style' ) );
$button_style = arr2str( get_sub_field( 'button_style' ) );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.