我正在尝试连接两种自定义帖子类型。通过大量的google搜索,我发现了下面的代码,它在管理屏幕上添加了一个元框,以从另一种帖子类型中选择一篇帖子作为父级,但是如何在数据库中将该帖子设置为父级呢?
add_action(\'admin_menu\', function() {
remove_meta_box(\'pageparentdiv\', \'episodes\', \'normal\');
});
add_action(\'add_meta_boxes\', function() {
add_meta_box(\'episodes-parent\', \'Cartoon Series\', \'episodes_attributes_meta_box\', \'episodes\', \'side\', \'default\');
});
function episodes_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {
$pages = wp_dropdown_pages(array(\'post_type\' => \'cartoon-series\', \'selected\' => $post->post_parent, \'name\' => \'parent_id\', \'show_option_none\' => __(\'(no parent)\'), \'sort_column\'=> \'menu_order, post_title\', \'echo\' => 0));
if ( ! empty($pages) ) {
echo $pages;
} // end empty pages check
} // end hierarchical check.
}
谢谢!