Support

Account

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' ) );