有人知道是否有一种方法可以处理nav_menu_item
内置post类型?当我将自定义分类法分配给此帖子类型时,我在菜单编辑器中看不到任何更改。。。它与posts
, pages
和custom post types
.
以下是我如何注册自定义分类法:
add_action( \'init\', \'my_region_taxo\', 0 );
function my_region_taxo() {
$labels = array(
\'name\' => _x( \'Regions\', \'Taxonomy General Name\', \'my-text-domain\' ),
\'singular_name\' => _x( \'Region\', \'Taxonomy Singular Name\', \'my-text-domain\' ),
(...)
);
$rewrite = array(
\'slug\' => \'region\',
\'with_front\' => true,
\'hierarchical\' => true,
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => false,
\'show_tagcloud\' => false,
\'rewrite\' => $rewrite,
\'show_in_rest\' => true,
);
register_taxonomy(
\'my_region_taxonomy\',
array(
\'post\',
\'page\',
\'nav_menu_item\'
),
$args
);
}
最合适的回答,由SO网友:Jacob Peattie 整理而成
这并不是允许将分类术语添加到菜单的方式。要做到这一点,您只需设置show_in_nav_menus
到true
注册分类时。您已将其设置为false
.
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true, // This
\'show_tagcloud\' => false,
\'rewrite\' => $rewrite,
\'show_in_rest\' => true,
);
register_taxonomy(
\'my_region_taxonomy\',
array(
\'post\',
\'page\', // Not here
),
$args
);
您的分类法实际上不应该是
nav_menu_item
岗位类型。