• Resolved Daniel Gilfoy

    (@dgilfoy)


    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

    (@dgilfoy)

    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.