0

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 1

0

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 />";
    }
4
  • 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, 2012 at 9:18
  • The second example showed nothing.
    – prochevnik
    Apr 7, 2012 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.
    – Adam
    Apr 7, 2012 at 11:04
  • Thank you! I appreciate your help. That worked perfectly.
    – prochevnik
    Apr 7, 2012 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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