好吧,我花了一段时间,但我想我已经做到了。我不得不使用usort。我还包括了get_top_level_pages()
方法
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array(\'post_type\' => \'page\', \'posts_per_page\' => \'-1\'));
$top_level_pages = get_page_by_title(\'Locations\');
$menuArray = get_page_children( $top_level_pages->ID, $all_wp_pages );
function compareOrder($a, $b) {
return $a->menu_order - $b->menu_order;
}
usort($menuArray, \'compareOrder\');
或者,正如我后来发现的那样,我可以将数组中的最后一个值替换为:
public function create_custom_menu() {
$menuArray = $this->get_top_level_pages();
foreach ($menuArray as $key => $value) {
add_menu_page(
$value->post_title,
$value->post_title,
\'manage_options\',
$value->post_name.\'-admin-page\',
array( $this, \'create_admin_page\'),
\'dashicons-admin-home\' ,
$value->page_attributes->menu-order
);
}
}
或者更简单,我可以加上
\'orderby\'=>\'menu_order\'
我最初的查询。