WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pasing String (4 posts)

  1. MaddTechWF
    Member
    Posted 3 years ago #

    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?

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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>';
      }
  3. MaddTechWF
    Member
    Posted 3 years ago #

    When I implement the above code, I get the word bit on each one of my list items. What am I doing wrong?

  4. MaddTechWF
    Member
    Posted 3 years ago #

    Found it. Forgot the $ between the . and the b.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.