如果将metabox的值设置为authors cpt post id,则应该能够使用
//get the id for the actors cpt
$actors_id = get_post_meta( $post->ID, \'nt_getactors\', true );
//get the post obejct for the author
$actors_post = get_post( $actors_id, OBJECT ); //or ARRAY_A if you want an array and not an object
//to output e.g. the title use
$actors_post->post_title;
请参见
get_post 更多选项。
更新更改
$post_options [ $post->post_title ] = $post->post_title;
至
$post_options [ $post->ID ] = $post->post_title;
更新2使用
$actors_post
post对象与普通post对象一样。检查
the codex 获取可用成员变量的良好引用。
e、 g。
$actors_post->post_content;
请记住,$actors\\u post数据是“原始”的,您可能需要对其应用一些过滤器,这取决于您使用它的方式;e、 g。
apply_filters( \'the_content\', $actors_post->post_content );
更新3以从演员帖子中获取元值,可以对单个值执行此操作
get_post_meta( $actor_post->ID, \'ecpt_bio\', true );
或者(如果有多个值,可以在一个数组中获取所有值),如下所示:
$actor_meta = get_post_meta( $actor_post->ID );
//and then access the array element
echo $actor_meta[\'ecpt_bio\'];
将回调函数更改为引用帖子的id而不是标题(请参见更新#1)
//get the id for the actors cpt
$actors_id = get_post_meta( $post->ID, \'nt_getactors\', true );
//get the post obejct for the author
$actors_post = get_post( $actors_id, OBJECT );
//to output e.g. the title use
echo apply_filters( \'the_title\', $actors_post->post_title );
//output the content
echo apply_filters( \'the_content\', $actors_post->post_content );
//get the meta values from the actor post
$actor_meta = get_post_meta( $actor_post->ID );
//and output it like this
echo $actor_meta[ \'ecpt_bio\' ];