0

I'm trying to get the post_meta from a specific post. However: the following code breaks my document:

    $img= get_post_meta('4996','ATHLETE-side_img';

Then further down in the code I was planning to use $img as an img source.

Any help?

8
  • you are missing the closing ). Should be $img = get_post_meta( '4996', 'ATHLETE-side_img' );.
    – Abhik
    Commented Nov 27, 2015 at 10:47
  • @Abhik now my page isn't broken, but echo "<img src='" . $img . "'/> still doesn't display the image, any suggestions?
    – vlovsky
    Commented Nov 27, 2015 at 10:49
  • I get img src "Array"
    – vlovsky
    Commented Nov 27, 2015 at 10:51
  • in postmeta table your meta is same as "ATHLETE-side_img" or it is different like "_ATHLETE-side_img" ? Commented Nov 27, 2015 at 10:51
  • 1
    This should work: $img = get_post_meta( '4996', 'ATHLETE-side_img', true );
    – Abhik
    Commented Nov 27, 2015 at 10:51

1 Answer 1

1

You're missing a closing parenthesis, but you also need to set $single to true, otherwise the function will return an array of meta entries for the key (even if there is only one):

get_post_meta( 4996,'ATHLETE-side_img', true /* $single */ );
2
  • Thank you, this is also what Abhik just found, thanks for your time!
    – vlovsky
    Commented Nov 27, 2015 at 10:58
  • Please mark it as a valid answer, anyway, so other users might find it and understand that it works.
    – flomei
    Commented Nov 27, 2015 at 15:21

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