Doing work on CustomPress Output

So here's the issue I've got. I've used custompress to create a multiline text field. The idea here is to list the songs of an album in a list format. The problem I'm running into is that custompress's shortcodes treat the input as a single paragraph element. So when I check the inspector the line breaks are, indeed, preserved but they're output as a single line.

What I'd like to do then, is write a short bit of php in my "albums" template that would take the single paragraph element, explode it into an array, and output that array into a div of my own design.

So my first question then is how can I get the output of the custom fields? Can I just use get_custom_fields?

So something like this?

<?php

  $custom_fields = get_post_custom($post_id);
  $my_custom_field = $custom_fields['custom_field']; // I assume this will just have the one string in its array?
$songsList = preg_split('/\r\n|\r|\n/', $my_custom_field[0]); // this should give me an array of strings divided accordingly yeah?
echo '<div class="song-list">';
foreach ($song as $key => $songTitle)
{
   echo '<div class="album-song">' . ($key + 1) . '. ' . $songTitle . '</div>';
}
echo "</div>"

?>

Is that right? I'm not used to getting information from WP yet.

  • Adam

    I actually managed to resolve this. I wanna contribute my code in case anyone else comes up with the same question.

    <?php
     $songList =  get_post_meta( get_the_ID(), ID_OF_CUSTOM_FIELD ,true); //Make sure to flag this true otherwise it'll return an array.
     $songList = preg_split('/\r\n|\r|\n/', $songList); //returns an array of strings
      echo '<ol class="song-list">';
        foreach ($songList as $key => $song)
           {
                 echo '<li class="album-song">' . $song . '</li>'
            }
             echo '</ol>';
      ?>

    Some caveats: get_the_ID() only functions in the loop, so if you've got to get this information outside of the loop for some reason, it's not going to be there.