I have a custom Metabox. It allows multiple words separated by a ,. How can I write a loop to write each item to a UL list?
I have a custom Metabox. It allows multiple words separated by a ,. How can I write a loop to write each item to a UL list?
explode the string to form an array; then loop with a foreach loop.
http://php.net/manual/en/function.explode.php
http://php.net/manual/en/control-structures.foreach.php
example:
$string = from metabox, use whatever code
$bits = explode(',', $string);
if($bits) {
echo '<ul>';
foreach( $bits as $bit ) {
echo '<li>'.bit.'</li>';
}
echo '</ul>';
}When I implement the above code, I get the word bit on each one of my list items. What am I doing wrong?
Found it. Forgot the $ between the . and the b.
This topic has been closed to new replies.