Taxonomy is not working

2019-06-07 15:58发布

I have created a post type called blogs with categories and a taxaonomy called "blog name"... Posts are showing in categories but in taxonomies posts are not shown.

I am new to taxanomies... I have pasted the code here

function create_post_type_blogs() {

    $labels = array(
        'name' => _x('Blog Posts', 'post type general name', THEMEDOMAIN),
        'singular_name' => _x('Posts', 'post type singular name', THEMEDOMAIN),
        'add_new' => _x('Add New Post ', 'book', THEMEDOMAIN),
        'add_new_item' => __('Add New Post', THEMEDOMAIN),
        'edit_item' => __('Edit Post', THEMEDOMAIN),
        'new_item' => __('New Post', THEMEDOMAIN),
        'view_item' => __('View Posts', THEMEDOMAIN),
        'search_items' => __('Search Posts', THEMEDOMAIN),
        'not_found' =>  __('No Posts found', THEMEDOMAIN),
        'not_found_in_trash' => __('No Posts found in Trash', THEMEDOMAIN), 
        'parent_item_colon' => ''
    );      
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor', 'thumbnail', 'comments','author'),
        'taxonomies'  => array( 'blogname', 'category', 'post_tag' ),
        'menu_icon' => get_stylesheet_directory_uri().'/functions/images/sign.png'
    );




    register_post_type( 'blogs', $args );
} 


add_action('init', 'create_post_type_blogs', 0 );


// Register Custom Taxonomy
function add_taxonomy_blogname()  {
    $labels = array(
        'name'                       => 'Blog Name',
        'singular_name'              => 'Blog Name',
        'menu_name'                  => 'Blog Name',
        'all_items'                  => 'All Blog Names',
        'new_item_name'              => 'New Blog Name',
        'add_new_item'               => 'Add New Blog Name',
        'edit_item'                  => 'Edit Blog Name',
        'update_item'                => 'Update Blog Name',
        'separate_items_with_commas' => 'Separate Blog Name with commas',
        'search_items'               => 'Search Blog Name',
        'add_or_remove_items'        => 'Add or remove Blog Name',
        'choose_from_most_used'      => 'Choose from the most used Blog Name'

    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true
    );

    register_taxonomy( 'blogname', 'blogs', $args );
}

add_action( 'init', 'add_taxonomy_blogname', 0 );

1条回答
Fickle 薄情
2楼-- · 2019-06-07 16:48

Add this code on your function.php & Generate blog custom post type

add_action( 'init', 'create_blog_post_type' );

function create_blog_post_type() {

register_post_type( 'blog',

array(

    'labels' => array(

        'name' => _x( 'Blog', 'post type general name', 'livepulse' ),

        'singular_name' => __( 'Blog', 'post type singular name', 'livepulse' ),

        'add_new' => _x('Add New', 'blog', 'livepulse' ),

        'add_new_item' => __('Add New', 'livepulse' ),

        'edit_item' => __('Edit', 'livepulse' ),

        'new_item' => __('New', 'livepulse' ),

        'all_items' => __('View Posts'),

        'view_item' => __('View', 'livepulse' ),

        'search_items' => __('Search', 'livepulse' ),

        'not_found' =>  __('No post found', 'livepulse' ),

        'not_found_in_trash' => __('No post found in Trash', 'livepulse' ), 

        'parent_item_colon' => '',

        'menu_name' => _x( 'Blog', 'livepulse' ),

    ),

    'public' => true,

    'has_archive' => true,

    'rewrite' => array('slug' => 'blog'),

    'supports' => array('title','editor','thumbnail','page-attributes','comments'),


));
flush_rewrite_rules();

register_taxonomy('blog_category','blog',

array(

    'hierarchical' => false,

    'labels' => array(

        'name' => _x( 'Categories', 'taxonomy general name', 'livepulse' ),

        'singular_name' => _x( 'Blog', 'taxonomy singular name', 'livepulse' ),

        'search_items' =>  __( 'Search Blog', 'livepulse' ),

        'popular_items' => __( 'Popular Blog', 'livepulse' ),

        'all_items' => __( 'All Categories', 'livepulse' ),

        'parent_item' => null,

        'parent_item_colon' => null,

        'edit_item' => __( 'Edit Blog', 'livepulse' ), 

        'update_item' => __( 'Update Blog', 'livepulse' ),

        'add_new_item' => __( 'Add New Categories', 'livepulse' ),

        'new_item_name' => __( 'New Blog Name', 'livepulse' ),

        'separate_items_with_commas' => __( 'Separate Blog with commas', 'livepulse' ),

        'add_or_remove_items' => __( 'Add or remove Blog', 'livepulse' ),

        'choose_from_most_used' => __( 'Choose from the most used Blog', 'livepulse' )

    ),

    'hierarchical' => true,

    'query_var' => true,
    'rewrite' => array('slug' => 'blogascategory'),
)

);
flush_rewrite_rules();

register_taxonomy('blog-tag',array('blog'),
array
(
'hierarchical' => false,
'labels' => array
(
    'name' => _x( 'Tags', 'taxonomy general name' ),
    'singular_name' => _x( 'blog', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Tags' ),
    'all_items' => __( 'All Tags' ),
    'edit_item' => __( 'Edit Tag' ), 
    'update_item' => __( 'Update Tag' ),
    'add_new_item' => __( 'Add New Tag' ),
    'new_item_name' => __( 'New Tag Name' ),
    'menu_name' => __( 'Tags' ),
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'blog-tag', 'with_front' => true),
)
);
flush_rewrite_rules();
}

enter image description here

查看更多
登录 后发表回答