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)
Viewing 1 replies (of 1 total)
- The topic ‘Adding Custom columns for Custom Post type’ is closed to new replies.