Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created March 9, 2016 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/e4d6330f38fd18b60d30 to your computer and use it in GitHub Desktop.
Save tripflex/e4d6330f38fd18b60d30 to your computer and use it in GitHub Desktop.
Output standard text field with space or comma separated values with line break (or custom HTML) after each item
<?php
$field_values = get_custom_field( 'field_meta_key' );
if( ! empty( $field_values ) ){
// The default in code below is to output a line break HTML (<br />) after each item,
// if you want to use something else or different HTML, just replace <br /> below
// Use this to support "one two three four" ... values separated by space
// Remove the "//" before $field_values right below this line, and comment out the $field_values about 3 or 4 lines down
//$field_values = str_replace( " ", "<br />", $field_values );
// Use this to support "one, two, three, four" and "one,two,three,four" ... values separated by comma (with or without space)
$field_values = str_replace(" ", "", str_replace( ",", "<br />", $field_values ) );
echo $field_values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment