Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
Created June 5, 2024 14:33
Show Gist options
  • Save hereswhatidid/6a7aa79e5744bd0b3342cac4e84cfa08 to your computer and use it in GitHub Desktop.
Save hereswhatidid/6a7aa79e5744bd0b3342cac4e84cfa08 to your computer and use it in GitHub Desktop.
ACF Textarea to array by newlines
<?php
/**
* Add `array`, `arrayupper`, and `arraylower` options to textarea output
*
* @param $value
* @param $post_id
* @param $field
* @return array|mixed
*/
add_filter( 'acf/format_value/type=textarea', function ( $value, $post_id, $field ) {
switch ( $field[ 'new_lines' ] ) {
case 'array':
return preg_split( "/\r\n|\n|\r/", $value );
case 'arrayupper':
return array_map( 'strtoupper', preg_split( "/\r\n|\n|\r/", $value ) );
case 'arraylower':
return array_map( 'strtolower', preg_split( "/\r\n|\n|\r/", $value ) );
}
return $value;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment