利奥,
Ravs向现有WP\\U Post\\U对象添加子导航是正确的,但如果您正在创建导航项目,然后想要向其添加子导航,则必须设置导航项目的db\\U id:
add_filter( \'wp_nav_menu_objects\', \'ravs_add_menu_parent_class\' );
function ravs_add_menu_parent_class( $items ) {
$animals = array (
\'title\' => \'Animals\',
\'menu_item_parent\' => 0,
\'ID\' => 999999999999876, //an unlikely, high number
\'db_id\' => 999999999999876, //an unlikely, high number
\'url\' => \'www.google.com?s=animals\'
);
$items[] = (object) $animals;
$cats = array (
\'title\' => \'Cats\',
\'menu_item_parent\' => 999999999999876,
\'ID\' => \'\',
\'db_id\' => \'\',
\'url\' => \'www.google.com/?s=cats\'
);
$items[] = (object) $cats ;
return $items;
}