Showing custom taxonomy column in custom posts type listings

前端 未结 4 1885
深忆病人
深忆病人 2021-02-13 06:44

I have created a custom post type named banners. Thereby I register a new taxonomy called location that specifies on which page the banner is t

4条回答
  •  面向向阳花
    2021-02-13 07:30

     //what version of wordpress you are using
     //since wp 3.5 you can pass parameter show_admin_column=>true
     // hook into the init action and call create_book_taxonomies when it fires
     add_action( 'init', 'create_book_taxonomies', 0 );
    
     // create two taxonomies, genres and writers for the post type "book"
     function create_book_taxonomies() {
     // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => _x( 'Genres', 'taxonomy general name' ),
        'singular_name'     => _x( 'Genre', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Genres' ),
        'all_items'         => __( 'All Genres' ),
        'parent_item'       => __( 'Parent Genre' ),
        'parent_item_colon' => __( 'Parent Genre:' ),
        'edit_item'         => __( 'Edit Genre' ),
        'update_item'       => __( 'Update Genre' ),
        'add_new_item'      => __( 'Add New Genre' ),
        'new_item_name'     => __( 'New Genre Name' ),
        'menu_name'         => __( 'Genre' ),
    );
    
    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'genre' ),
    );
    
    register_taxonomy( 'genre', array( 'book' ), $args );
     }
    

提交回复
热议问题