Support » Themes and Templates » Adding Custom Columns to Post Types?

  • jezThomp

    (@jezthomp)



    I have the following code in the functions.php adding a custom post type of Functions and custom for taxonomies Movies.

    // Custom Posts Type Features, including custom category name
    
    function post_type_features() {
    
     register_post_type('features',
      array(
        'labels' => array(
        'name' => __( 'Features' ),
        'singular_name' => __( 'Features' ),
        'add_new' => __( 'Add New' ),
        'add_new_item' => __( 'Add New Features' ),
        'edit' => __( 'Edit' ),
        'edit_item' => __( 'Edit Features' ),
        'new_item' => __( 'New Features' ),
        'view' => __( 'View Features' ),
        'view_item' => __( 'View Features' ),
        'search_items' => __( 'Search Features' ),
        'not_found' => __( 'No Features found' ),
        'not_found_in_trash' => __( 'No Features found in Trash' ),
        'parent' => __( 'Parent Features' ),
       ),
          'public' => true,
          'show_ui' => true,
       'exclude_from_search' => true,
       'hierarchical' => true,
       'supports' => array( 'title', 'editor', 'thumbnail' ),
       'query_var' => true
       )
       );
     }
    
     add_action('init', 'post_type_features');
    
     add_action( 'init', 'create_features_taxonomies', 0 );
    
     function create_features_taxonomies()
     {
       // Add new taxonomy, make it hierarchical (like categories)
       $labels = array(
         'name' => _x( 'Movies', 'taxonomy general name' ),
         'singular_name' => _x( 'Name', 'taxonomy singular name' ),
         'search_items' =>  __( 'Search Names' ),
         'popular_items' => __( 'Popular Names' ),
         'all_items' => __( 'All Names' ),
         'parent_item' => __( 'Parent Name' ),
         'parent_item_colon' => __( 'Parent Name:' ),
         'edit_item' => __( 'Edit Name' ),
         'update_item' => __( 'Update Name' ),
         'add_new_item' => __( 'Add New Movie' ),
         'new_item_name' => __( 'New Name Movie' ),
       );
       register_taxonomy('Names',array('features'), array(
         'hierarchical' => true,
         'labels' => $labels,
         'show_ui' => true,
         'query_var' => true,
         'rewrite' => array( 'slug' => 'Names' ),
       ));
     }

    Is there any way i can add some custom columns for the page in the admin where it lists all the posts?

Viewing 1 replies (of 1 total)
  • Maybe you can work with this? Its how I list my custom post type (ve_products), with its costom taxonomy (prod_cat) and display excerpt of post

    // ADDS EXTRA INFO TO ADMIN MENU FOR PRODUCT POST TYPE
    add_filter("manage_edit-ve_products_columns", "voodoo_prod_edit_columns");
    add_action("manage_posts_custom_column", "voodoo_prod_custom_columns");
    
    function voodoo_prod_edit_columns( $columns ) {
    
    	// Add the extra column for product categories instead of rebuilding the whole array
    	$columns["prod_cat"] = "Product Category";
    
    	return $columns;
    }
    
    function voodoo_prod_custom_columns( $column ) {
    	global $post;
    	switch( $column ) {
    		case "description":
    			the_excerpt();
    		break;
    		case "prod_cat":
    			echo get_the_term_list( $post->ID, 'product_category', '', ', ', '' );
    		break;
    	}
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Adding Custom Columns to Post Types?’ is closed to new replies.