我怀疑这不是您的代码,因为您的代码中确实有很多错误。我要把它们列出来
首先,您要在一个钩住的函数中注册自定义帖子类型init
, 这很好。然后在该函数之外注册分类法。我不知道这是什么原因。您应该在函数中注册分类法和自定义帖子类型,因为您的分类法已注册到自定义帖子类型
其次register_taxonomy( $taxonomy, $object_type, $args );
看起来像这样。这个$object_type
参数,尽管获取数组或字符串只能是字符串,因为您只需将分类注册到one 自定义帖子类型
第三,在event_cat
分类法,此行\'labels\' => array(
丢失了,破坏了一切
第四,在event_tag
分类学,有一块this */
虚无也会破坏你的密码
最后,如果这是您的代码,您不应该注册类别和标记。下面是注册类别和标记的代码
register_taxonomy_for_object_type(\'category\', \'event_type\');
register_taxonomy_for_object_type(\'post_tag\', \'event_type\');
因此,在所有这些之后,您的代码应该是
function event_post_example() {
register_post_type( \'event_type\',
array(
\'labels\' => array(
\'name\' => __(\'Events Posts\', \'baretheme\'),
\'singular_name\' => __(\'Event Post\', \'baretheme\'),
\'all_items\' => __(\'All Event Posts\', \'baretheme\'),
\'add_new\' => __(\'Add New Event Post\', \'baretheme\'),
\'add_new_item\' => __(\'Add New Event Type\', \'baretheme\'),
\'edit\' => __( \'Edit\', \'baretheme\' ),
\'edit_item\' => __(\'Edit Post Types\', \'baretheme\'),
\'new_item\' => __(\'New Post Type\', \'baretheme\'),
\'view_item\' => __(\'View Post Type\', \'baretheme\'),
\'search_items\' => __(\'Search Post Type\', \'baretheme\'),
\'not_found\' => __(\'Nothing found in the Database.\', \'baretheme\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\', \'baretheme\'),
\'parent_item_colon\' => \'\'
), /* end of arrays */
\'description\' => __( \'This is the example event post type\', \'baretheme\' ), /* Custom Type Description */
\'public\' => true,
\'publicly_queryable\' => true,
\'exclude_from_search\' => false,
\'show_ui\' => true,
\'query_var\' => true,
\'menu_position\' => 9,
\'menu_icon\' => get_stylesheet_directory_uri() . \'/library/images/custom-post-icon.png\',
\'rewrite\' => array( \'slug\' => \'event_type\', \'with_front\' => false ),
\'has_archive\' => \'event_type\',
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'sticky\')
) /* end of options */
); /* end of register post type */
register_taxonomy( \'event_cat\',\'event_type\',
array(
\'labels\' => array(
\'name\' => __( \'Event Categories\', \'baretheme\' ),
\'singular_name\' => __( \'Event Category\', \'baretheme\' ),
\'search_items\' => __( \'Search Event Categories\', \'baretheme\' ),
\'all_items\' => __( \'All Event Categories\', \'baretheme\' ),
\'parent_item\' => __( \'Parent Event Category\', \'baretheme\' ),
\'parent_item_colon\' => __( \'Parent Event Category:\', \'baretheme\' ),
\'edit_item\' => __( \'Edit Event Category\', \'baretheme\' ),
\'update_item\' => __( \'Update Event Category\', \'baretheme\' ),
\'add_new_item\' => __( \'Add New Event Category\', \'baretheme\' ),
\'new_item_name\' => __( \'New Event Category Name\', \'baretheme\' )
),
\'hierarchical\' => true,
\'show_admin_column\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'event-slug\' ),
)
);
register_taxonomy( \'event_tag\',\'event_type\',
array(
\'labels\' => array(
\'name\' => __( \'Event Tags\', \'baretheme\' ),
\'singular_name\' => __( \'Event Tag\', \'baretheme\' ),
\'search_items\' => __( \'Search Event Tags\', \'baretheme\' ),
\'all_items\' => __( \'All Event Tags\', \'baretheme\' ),
\'parent_item\' => __( \'Parent Event Tag\', \'baretheme\' ),
\'parent_item_colon\' => __( \'Parent Event Tag:\', \'baretheme\' ),
\'edit_item\' => __( \'Edit Event Tag\', \'baretheme\' ),
\'update_item\' => __( \'Update Event Tag\', \'baretheme\' ),
\'add_new_item\' => __( \'Add New Event Tag\', \'baretheme\' ),
\'new_item_name\' => __( \'New Event Tag Name\', \'baretheme\' )
),
\'hierarchical\' => false,
\'show_admin_column\' => true,
\'show_ui\' => true,
\'query_var\' => true,
)
);
}
add_action( \'init\', \'event_post_example\');