父页面列表
根据您的屏幕截图,它使用的是经典编辑器,您可以使用
get_pages() 和
get_pages hook 达到目的。
页面属性元框由page\\u attributes\\u meta\\u box()创建,它使用wp\\u dropdown\\u pages()、wp\\u dropdown\\u pages(),然后使用get\\u pages()加载页面以创建选项如果我理解正确,您希望添加原始post type Page
自定义帖子类型父列表。以下方法可以将任何其他帖子类型添加到不同的帖子类型。示例显示的是添加Page.
add_filter( \'get_pages\', \'ws361150_add_page_to_parent_list\', 10, 2 );
function ws361150_add_page_to_parent_list( $post_type_pages, $parsed_args ) {
// if this is not admin page, return, since get_page is used in also navigation list in frontend
// avoid unnecessary rendering
global $current_screen;
// check to see if it is in edit post type page
// you may specify the post type $specify_post_type, if add to all custom post types, just leave it blank, if add to certain post types, use preg_match instead of strpos
$specify_post_type = \'\';
if( empty( $current_screen ) || ! empty( $current_screen ) && is_bool( strpos( $current_screen->parent_file, "edit.php?post_type={$specify_post_type}" ) ) ) {
return $post_type_pages;
}
// add Page\'s page list to current page list or any post types
$additional_post_type = \'page\';
$found_page = false;
// *** because it is a filter, need to check if it is already merge, if not doing this, infinite loop will occur
foreach ($post_type_pages as $key => $page) {
if( $page->post_type === $additional_post_type ) {
// var_dump(\'found\');
$found_page = true;
break; // no need to continue if found
}
}
if( $found_page ) {
return $post_type_pages;
} else {
// add page list to current post type pages
$args = array(
\'post_type\' => \'page\',
\'exclude_tree\' => $_REQUEST[\'post\'],
);
$page_list = get_pages( $args ); // call again get_pages, the above test will return the page list without looping to add if it is already done
$pages = array_merge( $page_list, $post_type_pages );
// var_dump(\'add once\');
return $pages;
}
}