0

Im using Reusable Metaboxes (old but still works) and I created a metabox that allows the user to pick a post from a list of custom post types. Right now that works pretty well, I can see all the posts in a list and I pick one and save.

The data I see when I call the_meta() shows me that the field is indeed saving the id of the post I called:

episode_guestid: a:1:{i:0;s:2:"18";}

But I don't know how to get the id (in this case 18 - and this needs to be dynamic depending on the chosen post) and use it to display things from that post: title, featured image, metaboxes content.

Tried the "easiest one" with no success (so I will need help with figuring out how to display the metabox data from that post as well):

$guestid = $post_meta_data['episode_guestid'][0]; ?>
<h1> Featuring: <?php echo unserialize($guestid);  ?> </h1>

Hope someone can help me out with this one. Thanks!

1

the_meta is a very bare-bones method. The return value you're seeing is raw, unserialized data. WordPress uses PHP serialization to store complex values like Arrays and Objects as a string value. Have a look at get_post_meta:

$guest_id   = get_post_meta( get_the_ID(), 'episode_guestid', true );
$guest_post = get_post( $guest_id[0] );
echo '<pre>';
print_r( $guest_post );

You should see the post you're looking for. Let me know if that doesn't work.

  • yes, I see all the details of the post I chose :D thanks! now... if you have the time to point me into the right direction to actually get info from the post like title or a metabox that would be amazing. – Cynthia Lara Feb 7 at 18:25
  • 1
    I see echo get_the_title($guest_post); works! :D I will try to do more tests with other info and accept this answer – Cynthia Lara Feb 7 at 18:26
  • Thanks! You can use methods like get_the_title, which you've found, and get_the_content, get_the_post_thumbnail, etc. – phatskat Feb 7 at 20:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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