I have been following this post exactly: https://wordpress.stackexchange.com/a/19852/14957 and have everything working in the backend but when I try to use echo get_post_meta($post->ID, 'songs', true);
in my template all that is shown is Array
. Any ideas? I would appreciate it.
1 Answer
You might wish to try;
<?php
$mykey_values = get_post_custom_values('my_key');
foreach ( $mykey_values as $key => $value ) {
echo "$key => $value ('my_key')<br />";
}
?>
Where my_key would be equal to songs.
Another example of what I might do in a situation where I am dealing with multiple values;
<?php
global $post;
$meta = get_post_custom_values($post->ID, 'songs', true );
foreach ( $meta as $value ) {
echo $value . "<br />";
}
?>
Update: Try the following instead, which will cycle through each title and track of your 'songs' post meta.
global $post;
$meta = get_post_meta($post->ID, 'songs', true );
foreach ( $meta as $key => $value ) {
echo $value['title'] . "<br />";
echo $value['track'] . "<br />";
}
-
Ok, I tried your first example and seemed to get further than the second. Now, instead of just showing Array, it shows 0 => a:5:{i:0;a:2:{s:5:"title";s:13:"Song Name";s:5:"track";s:1:"1";}i:1;a:2:{s:5:"title";s:18:"Song Name";s:5:"track";s:1:"2";}i:2;a:2:{s:5:"title";s:4:"Song Name";s:5:"track";s:1:"3";}i:3;a:2:{s:5:"title";s:13:"Song Name";s:5:"track";s:1:"4";}i:4;a:2:{s:5:"title";s:30:"Song Name";s:5:"track";s:1:"5";}} ('songs') So it is showing what I have filled out in the backend just mashed up in that. Apr 7, 2012 at 9:18
-
-
@prochevnik Please try the following, this will give you the title and the track from 'songs'.
global $post; $meta = get_post_meta($post->ID, 'songs', true ); foreach ( $meta as $key => $value ) { echo $value['title'] . "<br />"; echo $value['track'] . "<br />"; }
- added code above for clarity.– AdamApr 7, 2012 at 11:04 -