自定义类别元变量无法正常工作

时间:2014-09-13 17:29:05

标签: wordpress custom-post-type taxonomy

我在function.php中添加了一些自定义帖子类型和自定义分类法,效果很好。我为自定义帖子类型分配了一些分层和非分层的分类法(catagories& tags对吧?)。非分层分类法工作得很好,我可以在编辑帖子时在标签元数据库中添加新项目。但是,这对我的分层分类法不起作用!我不知道错误在哪里,但按钮"添加新的车辆类别"和"最常用的"不工作添加所有,你可以点击它们但没有加载。这是javascript的东西吗? here's an screenshot to show the metaboxes I'm talking about: 这是我注册的自定义帖子类型之一:

$labels = array(
        'name'                  => _x( 'Finished Projects', 'post type general name' ),
        'singular_name'         => _x( 'Finished Project', 'post type singular name' ),
        'menu_name'             => _x( 'Finished Projects', 'admin menu' ),
        'name_admin_bar'        => _x( 'Finished Project', 'add new on admin bar' ),
        'add_new'               => _x( 'Add New', 'Finished Project' ),
        'add_new_item'          => __( 'Add New Finished Project' ),
        'new_item'              => __( 'New Finished Project' ),
        'edit_item'             => __( 'Edit Finished Project' ),
        'view_item'             => __( 'View Finished Project' ),
        'all_items'             => __( 'All Finished Projects' ),
        'search_items'          => __( 'Search Finished Projects' ),
        'parent_item_colon'     => __( 'Parent Finished Projects:' ),
        'not_found'             => __( 'No Finished Projects found.' ),
        'not_found_in_trash'    => __( 'No Finished Projects found in Trash.' )
    );

    $args = array(
        'labels'                => $labels,
        'description'           => 'Page template for Finished Projects',
        'public'                => true,
        'publicly_queryable'    => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'finished_projects' ),
        'capability_type'       => 'post',
        'has_archive'           => true,
        'hierarchical'          => false,
        'menu_position'         => null,
        'supports'              => array('excerpt','comments','author'),
        'taxonomies'            => array('scales', 'manufacturers','product categories','vehicle categories','countries'),
    );

    register_post_type( 'finishedprojects', $args );

这是我注册的自定义分类法之一:

//Vehicle Categories
    $labels = array(
        'name'              => _x( 'Vehicles Categories', 'taxonomy general name' ),
        'singular_name'     => _x( 'Vehicle Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Vehicles Categories' ),
        'all_items'         => __( 'All Vehicles Categories' ),
        'parent_item'       => __( 'Parent Vehicle Category' ),
        'parent_item_colon' => __( 'Parent Vehicle Category:' ),
        'edit_item'         => __( 'Edit Vehicle Category' ),
        'update_item'       => __( 'Update Vehicle Category' ),
        'add_new_item'      => __( 'Add New Vehicle Category' ),
        'new_item_name'     => __( 'New Vehicle Category Name' ),
        'menu_name'         => __( 'Vehicle Categories' ),
    );

    $args = array( 
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'vehicle_categories' ), 
    );
    register_taxonomy( 'vehicle category', array( 'reviews','finishedprojects' ), $args );

你们需要更多信息还是这些信息足够?

谢谢!

1 个答案:

答案 0 :(得分:1)

从分类名称中删除空格。

为此,请替换:

register_taxonomy( 'vehicle category', array( 'reviews','finishedprojects' ), $args );

使用:

register_taxonomy( 'vehicle_category', array( 'reviews','finishedprojects' ), $args );

另外,替换:

'taxonomies'  => array('scales', 'manufacturers','product categories','vehicle categories','countries'),

使用:

'taxonomies' => array('scales', 'manufacturers','product_categories','vehicle_categories','countries'),