Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been following this post exactly: http://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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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 />";
    }
share|improve this answer
    
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. –  prochevnik Apr 7 '12 at 9:18
    
The second example showed nothing. –  prochevnik Apr 7 '12 at 9:19
    
@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. –  userabuser Apr 7 '12 at 11:04
    
Thank you! I appreciate your help. That worked perfectly. –  prochevnik Apr 7 '12 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.