Ive been looking for a way I can take a WordPress custom meta box’s content that is entered on each line and output said contents on each line instead of in a single line, example:
Mon
Tues
Wed
Thurs
Fri
Sat
Sun
The above days of the week are entered in a custom meta box and I can output the contents of the meta box in my single.php with:
<?php if ( 'custom_post_type' == get_post_type() ) :
$foobar_meta = get_post_meta( get_the_ID(), 'meta-textarea', true );
if( !empty( $foobar_meta ) ) : ?>
<div class="jedi">
<ul id="workload">
<li><?php echo $foobar_meta; ?></li>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
However when I run the code it outputs as: <li>Mon Tues Wed Thurs Fri Sat Sun</li>
. How can I target everything that is entered on a line and output individually as:
<li>Mon</li>
<li>Tues</li>
<li>Wed</li>
<li>Thurs</li>
<li>Fri</li>
<li>Sat</li>
<li>Sun</li>
Per my research I assume I would use an array()
with a foreach
but targeting each line I am having difficulties in what to use to call the meta box to run through. I did look on the codex but I didn’t see anything on how to target what I need. So how can I with PHP take content that is entered on a single line and display it’s look on the site?
Please see below code this may help you:
OR
You can use like this too
$newstring .= '<li>' . str_replace("n", '</li><li>', $single_string) . '</li>';
without loop and explode.