CUSTOM REGISTER_TAYNOMY INS未显示自定义导航菜单

时间:2016-12-02 作者:Saiful Islam

我正在使用wordpress自定义贴子和register\\u分类,下面是我的代码。


function epg_works_register() {
    $labels = array(
        \'name\' => __(\'Works\'),
        \'singular_name\' => __(\'Works\'),
        \'add_new\' => __(\'Add Works Item\'),
        \'add_new_item\' => __(\'Add New Works Item\'),
        \'edit_item\' => __(\'Edit Works Item\'),
        \'new_item\' => __(\'New Works Item\'),
        \'view_item\' => __(\'View Works Item\'),
        \'search_items\' => __(\'Search Works Item\'),
        \'not_found\' => __(\'No Works Items found\'),
        \'not_found_in_trash\' => __(\'No Works Items found in Trash\'),
        \'parent_item_colon\' => \'\',
        \'menu_name\' => __(\'Works\')
    );
    // Set other options for Custom Post Type

    $args = array(
        \'labels\'              => $labels,
        // Features this CPT supports in Post Editor
        \'supports\'            => array( \'title\', \'editor\'),

        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        */  
        \'hierarchical\'        => true,
        \'public\' => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'menu_position\'       => 5,
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => true,
        \'publicly_queryable\'  => true,
        \'capability_type\'     => \'post\',
    );

    // Registering your Custom Post Type
    register_post_type( \'works\', $args );

    register_taxonomy(\'works_category\', \'works\', array(\'hierarchical\' => true, \'label\' => \'Works Category\', \'query_var\' => true, \'rewrite\' => array(\'slug\' => \'works-categorys\')));

    flush_rewrite_rules();
}
add_action( \'init\', \'epg_works_register\');

如果我将register\\u taxonomy(\'works\\u category\'更改为register\\u taxonomy(\'something\'),则会显示http://localhost/wp-admin/nav-menus.php

但是如果使用register\\u分类法(“works\\u category”),那么我在那里看不到任何东西http://localhost/wp-admin/nav-menus.php.

怎么了?

谢谢

2 个回复
最合适的回答,由SO网友:Benoti 整理而成

我唯一看到的是论点\'query_var\'=>true, 可以将其设置为false,但默认值是分类名称,因此将其设置为true可能是失败的原因,即使是codex示例也可以将其设置为true,我认为可以尝试一下

 register_taxonomy(
      \'works_category\', 
      \'works\', 
           array(
                \'hierarchical\' => true, 
                \'label\' => \'Works Category\', 
                \'query_var\' => \'works_category\', 
                \'rewrite\' => array(\'slug\' => \'works-categorys\')
           )
 );
或者只是从数组中取消query\\u var?

SO网友:Fanky

这可能是因为register\\u分类法中的某些“功能”设置不正确。这些基于后期管理功能定义管理权限:

register_taxonomy(\'mycat\', \'mycustomtype\',
 array(
 //...,
 \'capabilities\' => array(
  \'manage_terms\' => \'manage_categories\',
  \'edit_terms\' => \'manage_categories\',
  \'delete_terms\' => \'manage_categories\',
  \'assign_terms\' => \'edit_posts\'
  )
 )
);

相关推荐

无法将设置添加到“NAV_MENUS”定制器面板

我试图在自定义程序的“菜单”面板中添加一个复选框,但由于某些原因,它没有显示出来。如果我尝试将其从“nav\\u菜单”更改为“title\\u tagline”或“colors”,复选框会显示得很好。是什么阻止它显示在“菜单”面板上?// add custom options to the Customizer function nssra_customizer_options($wp_customize) { // add \"menu primary flex\" checkb