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!
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!
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 Array
s and Object
s 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.