Data comes from WordPress metabox in a form of single long array.
The data that I insert in metabox looks like this:
Rhine Riesling1|0,75 l|9,50 &euro
Rhine Riesling2|0,75 l|9,50 &euro
Rhine Riesling3|0,75 l|9,50 &euro
Rhine Riesling4|0,75 l|9,50 &euro
Final output should look like this:
<ul class="listmenuitems" id="listingmenu_1">
<li><p>Rhine Riesling1 <span>0,75 l</span></p> <span class="listmenuprice">9,50 €</span></li>
<li><p>Rhine Riesling2 <span>0,75 l</span></p> <span class="listmenuprice">9,50 €</span></li>
<li><p>Rhine Riesling3 <span>0,75 l</span></p> <span class="listmenuprice">9,50 €</span></li>
<li><p>Rhine Riesling4 <span>0,75 l</span></p> <span class="listmenuprice">9,50 €</span></li>
</ul>
How would I cut the array values into pieces considering the separator | and then loop through it to create a correctly formatted <li><p>?
I’m reading about PHP’s explode() at the moment.
You can use the PHP explode command. http://php.net/manual/en/function.explode.php
Loop through your array, on each entry call: explode(“|”, $entry);
then you can print out what you want like so:
Note there is on error checking and it is assumed that you have a complete and well formed array input.
Updated to add foreach 😉
And if the foreach loop is your fancy…