簡體   English   中英

自定義帖子類型 - 類別添加按鈕不起作用

[英]Custom Post Type - Category Add Button Not Working

我創建了一個自定義帖子類型以及該帖子類型的自定義分類法。 一切似乎都在工作......除了當我去創建一個新帖子時,如果我點擊“+添加新類別”,它會更改 URL,但沒有任何反應。 所有其他 JS 按鈕都可以工作,並且在常規帖子上工作得很好……不知道為什么會這樣。 下面是我使用functions.php 文件的代碼。

注冊自定義帖子類型

/* Custom Post Type Galleries */

function bhgallery_register_post_type() {

    $singular = 'Gallery';
    $plural = 'Galleries';

    $labels = array (
        'name' => $plural,
        'singular' => $singular,
        'add_name' => 'Create New',
        'add_new_item' => 'Create New ' . $singular,
        'edit' => 'Edit',
        'edit_item' => 'Edit ' . $singular,
        'new_item' => 'New' . $singular,
        'view' => 'View' . $singular,
        'view_item' => 'View' . $singular,
        'search_term' => 'Search ' . $plural,
        'parent' => 'Parent ' . $singular,
        'not_found' => 'No ' . $plural . ' Found',
        'not_found_in_trash' => 'No ' . $plural . ' in Trash'

    );

    $args = array ( 
        'labels'                => $labels,
        'public'                => true,
        'public_queryable'      => true,
        'exclude_from_search'   => false,
        'show_in_nav_menus'     => true,
        'show_in_admin_bar'     => true,
        'menu_position'         => 10,
        'menu_icon'             => 'dashicons-camera',
        'can_export'            => true,
        'delete_with_user'      => false,
        'hierarchical'          => false,
        'has_archive'           => true,
        'query_var'             => true,
        'capability_type'       => 'post',
        'map_meta_cap'          => true,
        // 'capabilities' => array();
        'rewrite'               => array(
            'slug'          => 'gallery',
            'with_front'    => true,
            'pages'         => true,
            'feeds'         => false,
        ),
        'supports'              => array(
            'title',
            'thumbnail',
            'editor'
        )
    );

    register_post_type( 'bh_gallery', $args );

}

add_action ( 'init', 'bhgallery_register_post_type');

自定義分類

/** Custom Categories for Gallery **/

function bhgallery_register_taxonomy() {

    $plural = 'Categories';
    $singular = 'Category';

    $labels = array (
            'name'                      => $plural,
            'singular_name'             => $singular,
            'search_items'              => 'Search ' . $plural,
            'popular_items'             => 'Popular ' . $plural,
            'all_items'                 => 'All ' . $plural,
            'parent_item'               => null,
            'parent_item_colon'         => null,
            'edit_item'                 => 'Edit ' . $singular,
            'update_item'               => 'Update ' . $singular,
            'add_new_item'              => 'Add New ' . $singular,
            'new_item_name'             => 'New ' . $singular . ' Name',
            'separate_items_with_comas' => 'Seperate ' . $singular . ' with commas',
            'add_or_remove_items'       => 'Add or remove ' . $plural,
            'choose_from_most_used'     => 'Choose from the most used ' . $plural,
            'not_found'                 => 'No ' . $plural . 'fount',
            'menu_name'                 => $plural,
        );

    $args = array (
        'hierarchical'          => true,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'categories'),
        );

    register_taxonomy( 'gallery category', 'bh_gallery', $args );
}

add_action ( 'init', 'bhgallery_register_taxonomy');

如果您還有什么需要了解的,請告訴我。

你上面的倒數第二行代碼有

register_taxonomy( 'gallery category', 'bh_gallery', $args );

從 codex register taxonomy來看,第一個參數不應該有任何空格。 事實上,很少有地方允許使用空格,它們主要限於用於顯示的字符串。

$taxonomy (string) (required) 分類的名稱。 名稱應僅包含小寫字母和下划線字符,且長度不超過 32 個字符(數據庫結構限制)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM