作为解决方法,我有以下临时解决方案:
$the_menu = wp_get_nav_menu_object(\'Some Menu\');
$the_menu_items = wp_get_nav_menu_items($the_menu);
$category_products = [];
foreach ($the_menu_items as $index => $menu_category) {
if ($menu_category->object_id == $category->term_id ) {
$category_submenu = $menu_category;
}
}
foreach ($the_menu_items as $index => $menu_product) {
if ($menu_product->type_label == \'Product\'
&& $menu_product->menu_item_parent == $category_submenu->ID
) {
$category_products[] = $menu_product;
}
}
我正在解析所有菜单项(父项和子项),根据当前类别ID获取必要的项,然后通过再次解析所有项并检查当前项(产品)父ID是否与父类别项ID匹配来检索每个类别的子项(产品),我只是将其放入一个数组中。