Title: Adding Custom columns for Custom Post type
Last modified: August 19, 2016

---

# Adding Custom columns for Custom Post type

 *  Resolved [Daniel Gilfoy](https://wordpress.org/support/users/dgilfoy/)
 * (@dgilfoy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/adding-custom-columns-for-custom-post-type/)
 * I’ve been having some difficulty getting Custom Columns working.
 * I set up a simple “test” column like so:
 *     ```
       function post_type_testcols($cols){
       	$cols['testytest'] = "Test Column";
       	return $cols;
       }
   
       function fill_cols($col){
       	switch($col){
       		case "testytest":
       			echo "Test Works";
       			break;
       	}
       }
       ```
   
 * And not only does the new column show up under normal Posts just fine, so does
   the “Test Works” message, on each row. Great!
 * Now I add a simple Custom Post type:
 *     ```
       function test_post_type_init() {
   
       	$labels = array(
       		'name'=>__("Tests"),
       		'singular_name'=>__("Test"),
       		'add_new'=>__('New Test'),
       		'add_new_item'=>__('Add New '),
       		'edit_item'=>__('Edit Test'),
       		'new_item'=>__('Add New Test'),
       		'view_item'=>__('View Test'),
       		'search_items'=>__('Search Tests')
       	);
   
       	$supports = array('title','excerpt','thumbnail','comments');
   
       	$args = array(
       		'label'=> __('tests'),
       		'labels'=>$labels,
       		'public' => true,
       		'publicly_queryable' => true,
       		'show_ui' => true,
       		'query_var' => true,
       		'rewrite' => true,
       		'capability_type' => 'post',
       		'hierarchical' => true,
       		'menu_position' => 4,
       		'supports' => $supports
       	);
   
       	register_post_type('tests',$args);
       }
       add_action( 'init', 'test_post_type_init');
       ```
   
 * Column name shows up under Tests Post type, but the “Test Works” does not show
   up.
 * Nothing I’ve tried works.
 * Anybody have luck with Custom Post types and adding custom columns to them?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Daniel Gilfoy](https://wordpress.org/support/users/dgilfoy/)
 * (@dgilfoy)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/adding-custom-columns-for-custom-post-type/#post-1782868)
 * Crap, been searching for the solution for 4 days now and I just ran across [this comment](http://www.fldtrace.com/wordpress/wordpress-custom-post-types-custom-back-end-columns-and-post-thumbnails#comment-3374)
   after posting this and it worked.
 * The quote as follow:
 * > It’s good to note that you can’t change the columns of a post type that’s set
   > to “Page” or has “hierarchical => true”.
 * Which is weird, but I don’t need it to be hierarchical so problem solved! .

Viewing 1 replies (of 1 total)

The topic ‘Adding Custom columns for Custom Post type’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Daniel Gilfoy](https://wordpress.org/support/users/dgilfoy/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/adding-custom-columns-for-custom-post-type/#post-1782868)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
