What? What did you said on the title? Well, I am not sure this is an appropriate title. But I am going to explain it to you.
Lets say, you are making a theme or a WordPress plugin and you want to show something in the admin panel like this:
We will see how can you add those columns to the admin panel tables and manipulate data on the table rows. Well, this is very easy to do, because WP has a really nice API to work with.
Now we will add those two columns to our admin panel’s post listing table. Here is the code:
<?php
function test_modify_post_table( $column ) {
$column['test_budget'] = 'Budget';
$column['test_expires'] = 'Expires';
return $column;
}
add_filter( 'manage_posts_columns', 'test_modify_post_table' );
We are adding a filter on "manage_posts_columns". It passes the column names of the post table as an array. We simple add our custom columns with a key-value pair in that array and return it. If you run this code, you can see how easy that was.
Now we have the columns, we need to fill those columns with actual data. We’ll use post custom fields to fill those space. Lets look at the code:
<?php
function test_modify_post_table_row( $column_name, $post_id ) {
$custom_fields = get_post_custom( $post_id );
switch ($column_name) {
case 'test_budget' :
echo $custom_fields['cf_budget'][0] . ' USD';
break;
case 'test_expires' :
echo $custom_fields['cf_expires'][0] . ' days';
break;
default:
}
}
add_filter( 'manage_posts_custom_column', 'test_modify_post_table_row', 10, 2 );
We are adding another filter at "manage_posts_custom_column" with having two arguments. One is the column name and another is the post id. Then we are grabbing all the custom fields of the post and showing them according to the column name. The code is self explanatory. These columns will be visible to all of your "Post Type" listings.
For Custom Post Type:
If you have another "Custom Post Type", lets say "Tutorials", those columns will also be shown there. So, if you want to add those columns only to the Post’s table, not in other custom post types, you should add a checking option there. And if you only want to show those columns to a specific Custom Post Type, there is another hack. You need to change the first filter to something like this "manage_edit-POST_TYPE_columns". Replace the "POST_TYPE" with your custom post type. e.g: “manage_edit-portfolio_columns” for “portfolio” type posts.
For Pages:
For pages, those filter will be "manage_pages_columns" and “manage_pages_custom_column“. Simple enough.
User List table?
What if you want to change the user list table? It’s the same process as previous. We can add our custom columns like we did before. But the first filter name will be changed to codemanage_users_columnscode. Here there is a slight change in the second filter. We passed two parameter for the posts, but here we will pass THREE paramater. Here is the sample code to add a column "URL" to show their website addresses:
<?php
function test_modify_user_table( $column ) {
$column['url'] = 'URL';
return $column;
}
add_filter( 'manage_users_columns', 'test_modify_user_table' );
function test_modify_user_table_row( $val, $column_name, $user_id ) {
$user = get_userdata( $user_id );
switch ($column_name) {
case 'url' :
return $user->user_url;
break;
default:
}
return $return;
}
add_filter( 'manage_users_custom_column', 'test_modify_user_table_row', 10, 3 );
Hope you enjoyed

Did u able to add sorting function for custom col in user ?
I didn’t tried it. But there should be some workaround.
ok I am close, the hook will be like manage_{$screen->id}_sortable_columns here for user listing the screen id is users and the hook name will be manage_users_sortable_columns
this plugin’s code may help http://plugins.svn.wordpress.org/recently-registered/trunk/recently-registered.php
please check working code http://pastebin.com/yFP9paia
Cool
Hi pleas help me
I want to add few fields while posting in admin panel. My fields are like
a text box which has to be filled
a select box which will be populated from the table for example company
What I want is I want to put a column in the post table say for example “Add more” It will direct to a differnet page where I can add my values and the form will be like as I specified above
Please help me I am stucked
Thanks
One more question : Where to write these codes as I am new to wordpress
@SonalSharma You can write the codes in your themes functions.php or by creating a new plugin.
@SonalSharma I think it’s pretty straight forward and my codes are well explained. Just print the fields as I echo’d the budget/price in the codes.
Great information. Looks like just what I was looking for.
I would like to add the url to my user list table but not sure how to do it. I am new to coding and do not want to mess anything up.
Could you email me some detailed instructions on what, where and how to do this, or direct me to more information.
Thanks
Detailed instruction is already provided here. What do you want more?
If you rather not be coding, I might have a solution for you. I have just released a plugin which let’s you you manage the columns without any coding, hopefully it will be helpfull for you and others.
And great read btw Tareq! I have put the users columns on the todo list for a coming release.
You can find my Admin Column plugin here: http://wordpress.org/extend/plugins/codepress-admin-columns/
Cool plugin indeed, you did a great work
Thanks! I also added User columns to the latest release ( 1.1.1 and up ). You can set the user url as a column now.
Creating interfaces for users is always a tedious job and you did wonderful indeed
My 2 cents: First, the custom column row hook is an action, not a filter and second, to use that action into custom post types you should hook it to ‘manage_{post_type}_posts_custom_column’.
Hope it helps!
This is great but I want to add a column to the links table and not sure how to modify the code to do this. I’ve tried the code below and it doesn’t work, can anyone help?
function test_modify_links_table( $column ) {
$column['date'] = ‘Date Added’;
return $column;
}
add_filter( ‘manage_links_columns’, ‘test_modify_links_table’ );
function test_modify_links_table_row( $column_name, $link_id ) {
$custom_fields = get_bookmark( $link_id );
switch ($column_name) {
case ‘date’ :
echo $custom_fields['cf_date'][0];
break;
default:
}
}
add_filter( ‘manage_links_custom_column’, ‘test_modify_links_table_row’, 10, 2 );
After checking the `/wp-admin/includes/class-wp-links-list-table.php`, I don’t think that they provide any filter to modify the links list table
Thanks Tareq. That’s a shame.
I have discovered that there is an additional argument to pass to the get_bookmarks() function that supposedly brings back the updated date and time, so that functionality may already be there… http://codex.wordpress.org/Function_Reference/get_bookmarks
thanks for this tutorials.
i want to add custom comment meta in comment listing in admin ……can you suggest me how can i do that.????
Try this plugin
Thanx Tareq it’s working
Hi,
thanks for the code! Works quit nice! Except for one thing:
I use the following code to add the users appartment number to the user table.
function test_modify_user_table ($column) {$column['hnumber'] = __('House number', 'coolhaven');
return $column;
}
add_filter('manage_users_columns', 'test_modify_user_table');
function test_modify_user_table_row ($val, $column_name, $user_id) {
$user = get_userdata($user_id);
if ($column_name == 'hnumber') {
return $user->number;
}
}
add_filter('manage_users_custom_column', 'test_modify_user_table_row', 10, 3);
The code does create a new collumn, but does not put any text in the appropriate fields. I am sure the right data is collected because when I print_r(); the $user->number, it displays the number somewhere on the page.
Could you please help me figure out what’s wrong?
Best regards,
Irian
They way you used filters, everything seems right. Not sure whats coming wrong.
I am wanting this to display on my 5 custom post types. How can I add more than 1 custom post type to the filter?
Add the filter to each custom post types.
Nice filter. Do you know how to add a new table after users table to show statistics about country of my users?
Thanks
Unfortunately, there isn’t any hook available below the users table.
Hi there, thanks for this tutorial!
Do you know how to add each user’s comment count as a sortable column?
Thank you in advance,
Roselle