Wordpress导航错误未定义属性:WP\u Post\u Type:$term\u id
我遇到了一个问题,看起来有几个人遇到过,但没有人提出解决方案 当我使用wp_nav_menu()函数时,在创建自定义文章类型和自定义分类法后,会出现此问题。我只在我的存档页面上看到此错误,在那里我得到了错误:Wordpress导航错误未定义属性:WP\u Post\u Type:$term\u id,wordpress,wp-nav-menu-item,Wordpress,Wp Nav Menu Item,我遇到了一个问题,看起来有几个人遇到过,但没有人提出解决方案 当我使用wp_nav_menu()函数时,在创建自定义文章类型和自定义分类法后,会出现此问题。我只在我的存档页面上看到此错误,在那里我得到了错误: Notice: Undefined property: WP_Post_Type::$term_id in C:\WebServer\Bolton\wp-includes\nav-menu-template.php on line 350 当我将分类层次更改为false时,问题就停止了,
Notice: Undefined property: WP_Post_Type::$term_id in C:\WebServer\Bolton\wp-includes\nav-menu-template.php on line 350
当我将分类层次更改为false时,问题就停止了,尽管我需要它为true。我还可以通过编辑WordPress核心文件来停止错误:
/wp-includes/nav-menu-template.php
第349-361行,如果我将其包装为is_single()
因此,导航菜单模板无法获取查询的对象ID,因为它位于存档页上,并因此而给出错误。菜单仍然正确显示,尽管导航栏上有一个大的提示
该通知与我编辑的Wordpress导航菜单模板文件一起消失,尽管版本更新将打破这一点,因此我需要修复核心问题
对wp_nav_menu()的调用可以是普通的,也可以带有任何参数(名称、ID等)。错误相同
谢谢你抽出时间
这是我第一个发帖的问题,如果我做错了什么,我道歉
以下是我的CPT和分类注册:
// Register CPT's
$args = [
'label' => 'Services',
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-hammer',
'taxonomy' => 'locations'
];
register_post_type ("Services", $args);
// Register taxonomies
$labels = [
'name' => 'Locations',
'singular_name' => 'Location',
];
$args = [
'hierarchical' => true,
'labels' => $labels,
'public' => true,
'query_var' => true,
];
register_taxonomy ("locations", "services", $args);
// Register CPT's
$args = [
'label' => 'Services',
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-hammer',
'taxonomy' => 'locations'
];
register_post_type ("Services", $args);
// Register taxonomies
$labels = [
'name' => 'Locations',
'singular_name' => 'Location',
];
$args = [
'hierarchical' => true,
'labels' => $labels,
'public' => true,
'query_var' => true,
];
register_taxonomy ("locations", "services", $args);