$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - Get id from metabox dropdown|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - Get id from metabox dropdown

matteradmin10PV0评论

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!

Share Improve this question asked Feb 7, 2019 at 18:09 artist learning to codeartist learning to code 3311 gold badge5 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far