Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active August 29, 2015 14:15
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/67233784d9906ea637dd to your computer and use it in GitHub Desktop.
Save tripflex/67233784d9906ea637dd to your computer and use it in GitHub Desktop.
multi-select custom field as bulleted list ( foreach and implode examples )
// Start UL (Unordered List)
echo "<ul>";
// Get the field value
$amenities = get_custom_field( 'job_amentities' );
// Make sure there is a value
if( ! empty( $amentities ) ){
// An Array would be multiple selections
if( is_array( $amentities ) ){
// Loop through each one and output it in a LI (List Item)
foreach( $amenities as $amentity ){
echo "<li>" . $amentity . "</li>";
}
// One selection would be a single
} else {
echo "<li>" . $amentities . "</li>";
}
}
echo "</ul>";
// Start UL (Unordered List)
echo "<ul>";
// Get the field value
$amenities = get_custom_field( 'job_amentities' );
// Make sure there is a value
if( ! empty( $amentities ) ){
// An Array would be multiple selections
if( is_array( $amentities ) ){
// Loop through each one and output it in a LI (List Item)
echo "<li>" . implode( "</li><li>", $amentities ) . "</li>";
// One selection would be a single
} else {
echo "<li>" . $amentities . "</li>";
}
}
echo "</ul>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment