I have a custom post type called albums and a custom field therein called tracklist which is an array containing song_title and duration. I would like to print a list of the songs on each album.
It's helpful for me to think of the array hierarchy like so:
albumlist
album
tracklist
track
song_title
duration
So far I figured out how to drill down to the tracklist array, but not how to display the values of the song titles within it.
$albums = get_posts(array(
'post_type' => 'album',
'meta_key' => 'tracklist'
));
if($albums) {
foreach($albums as $album) {
echo get_the_title($album->ID) . "<br>"; // Displays album's title
$tracklist = get_post_custom_values('tracklist', $album->ID);
foreach($tracklist as $track) {
echo $track . "<br>"; // Displays "12" (there are 12 tracks on this album)
}
}
}
Anyway, I've been working at this for a couple hours trying to solve it myself, but it's getting late! Once I get to the tracklist array, how do I drill inside the track and get the song title?
Thanks for any help you can proffer.

get_post_custom_valuesgets all the custom fields for a post, if you want individual custom field, useget_post_metainstead. See my answer below. – Rutwick Gangurde Dec 20 '11 at 4:10get_post_metawould be the better choice here. If the asker couldprint_r()the meta data he gets, it would be alot easier for everyone to advise him or her on how to loop over that data(we need to see the structure of that data). – t31os Dec 20 '11 at 11:38