Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active May 26, 2022 01:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yoren/4553933 to your computer and use it in GitHub Desktop.
Save yoren/4553933 to your computer and use it in GitHub Desktop.
WordPress: Select post parent from another post type
add_action('admin_menu', function() {
remove_meta_box('pageparentdiv', 'chapter', 'normal');
});
add_action('add_meta_boxes', function() {
add_meta_box('chapter-parent', 'Part', 'chapter_attributes_meta_box', 'chapter', 'side', 'high');
});
function chapter_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' => 'part', '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.
}
@yoren
Copy link
Author

yoren commented Jan 4, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment