试试这个。
global $post; // if outside the loop
$page_object = get_queried_object();
$page_id = get_queried_object_id(); // Get current page id
$args = array(
\'sort_order\' => \'ASC\',
\'sort_column\' => \'post_title\',
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => $page_id,
\'meta_key\' => \'\',
\'meta_value\' => \'\',
\'authors\' => \'\',
\'child_of\' => 0,
\'parent\' => -1,
\'exclude_tree\' => \'\',
\'number\' => \'\',
\'offset\' => 0,
\'post_type\' => \'page\',
\'post_status\' => \'publish\'
);
$pages = get_pages($args);
$parentID = $pages[0]->post_parent; // Get current page parent id
这将为您提供当前页面父id,而不是顶级id
$parentID = $pages[0]->post_parent;