Skip to content

Instantly share code, notes, and snippets.

@chibani
Created January 11, 2012 14:26
Show Gist options
  • Save chibani/1594898 to your computer and use it in GitHub Desktop.
Save chibani/1594898 to your computer and use it in GitHub Desktop.
WordPress : adding custom columns in the posts list while using a custom post type
//This filter will allow us to add new columns
add_filter("manage_edit-mycustom_columns", "edit_columns");
//This action will populate the new columns
add_action("manage_posts_custom_column", "custom_columns");
/**
* First step : declaring the new columns (in this function, we could also remove the default columns...)
* @param array $columns
*/
function edit_columns($columns){
$columns['mycustom_col1'] = 'A neat title';
$columns['mycustom_col2'] = 'Another neat title';
return $columns;
}
/**
* Show the columns in the custom post list (in admin)
* @param string $column
*/
function custom_columns($column){
global $post;
$custom = get_post_custom_values($column,$post->ID);
switch($column){
case 'mycustom_col1':
//Here we can "play" with our data ... and then echo it
echo $custom[0];
break;
default:
echo $custom[0];
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment