Support » Fixing WordPress » Adding Custom columns for Custom Post type

  • Resolved Daniel Gilfoy


    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){
    		case "testytest":
    			echo "Test Works";

    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(
    		'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'),
    		'public' => true,
    		'publicly_queryable' => true,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'menu_position' => 4,
    		'supports' => $supports
    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)
  • Crap, been searching for the solution for 4 days now and I just ran across this comment 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.