在Wordpress上创建自定义文本和帖子类型


Create Custum Texonomy And Post Type On Wordpress

我正在尝试在wordpress上创建自定义onomy。如何创建它?

这是我的代码:

add_action( 'init', 'create_post' );
    function create_post() {
        $labels = array(
            'name' => _x('Post', 'Post General Name', 'gdl_back_office'),
            'singular_name' => _x('Speakpool Item', 'Post Singular Name', 'gdl_back_office'),
            'add_new' => _x('Add New', 'Add New Post Name', 'gdl_back_office'),
            'add_new_item' => __('Author Name', 'gdl_back_office'),
            'edit_item' => __('Author Name', 'gdl_back_office'),
            'new_item' => __('New Post', 'gdl_back_office'),
            'view_item' => '',
            'search_items' => __('Search Post', 'gdl_back_office'),
            'not_found' =>  __('Nothing found', 'gdl_back_office'),
            'not_found_in_trash' => __('Nothing found in Trash', 'gdl_back_office'),
            'parent_item_colon' => ''
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            //'menu_icon' => GOODLAYERS_PATH . '/include/images/portfolio-icon.png',
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => 5,
            "show_in_nav_menus" => false,
            'exclude_from_search' => true,
            'supports' => array('title','editor','author','thumbnail','excerpt','comments')
        ); 
        register_post_type( 'Post' , $args);
        register_taxonomy( 'Post_category', 'Post', array( 
            'hierarchical' => true, 'label' => 'Post Category', 'query_var' => true, "show_in_nav_menus" => true, 'rewrite' => true ) );
    }

它创建自定义帖子类型,但不是Texonomy不工作。

删除register_taxonomy()并尝试此代码代码更改您想要的名称:

function create_video_blog_taxonomies() {
    $labels = array(
        'name'              => _x( 'Video Categories', 'taxonomy general name' ),
        'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Categories' ),
        'all_items'         => __( 'All Categories' ),
        'parent_item'       => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item'         => __( 'Edit Category' ),
        'update_item'       => __( 'Update Category' ),
        'add_new_item'      => __( 'Add New Category' ),
        'new_item_name'     => __( 'New Category Name' ),
        'menu_name'         => __( 'Video Categories' ),
    );
    $args = array(
        'hierarchical'      => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'categories' ),
    );
    register_taxonomy( 'video_blog_categories', array( 'video_blog' ), $args );
}
add_action( 'init', 'create_video_blog_taxonomies', 0 );

分隔自定义帖子类型函数和Texomony函数