javascript - 自定义帖子类型 - 类别添加按钮不起作用

标签 javascript php wordpress

我创建了一个自定义帖子类型以及该帖子类型的自定义分类法。一切似乎都正常...除了当我去创建新帖子时,如果我单击“+ 添加新类别”,它会更改 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( '图库类别', 'bh_gallery', $args );

来自法典,register taxonomy ,第一个参数不应有任何空格。事实上,很少有地方允许使用空格,并且它们主要限于用于显示的字符串。

$taxonomy (string) (required) The name of the taxonomy. Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction).

关于javascript - 自定义帖子类型 - 类别添加按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33703638/

相关文章:

javascript - 单击按钮启动 Google 登录

javascript - Angularjs:从多个 Controller 捕获事件

javascript - 加载时加载额外的 html

php - 在子主题中文件 wc-template-functions.php

javascript - 如何使用内联函数调用在wordpress中调用javascript函数?

php - WordPress 选择查询不起作用

javascript - 'index.html' 中嵌入的“index.swf”在一页中两次显示同一网站。 HTML 标题标签/属性也显示值 'undefined'

php - Apache 和 MySQL 的 php 输出缓冲的性能影响

php - PHP 中的输入过滤

PHP 字符串分割