how to add custom column in wordpress

Posted: August 11, 2015 in Uncategorized
Tags: , , ,

add_action( ‘admin_init’, ‘my_admin_init’ );
function my_admin_init() {
add_filter( ‘manage_edit-leave_columns’, ‘my_new_custom_post_column’);
add_action( ‘manage_leave_posts_custom_column’, ‘location_tax_column_info’, 10, 2);
}

function my_new_custom_post_column( $column ) {
$column[‘leave_type’] = ‘Leave Type’;

return $column;
}

function location_tax_column_info( $column_name, $post_id ) {

if($column_name==’leave_type’){
//$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, ‘leave_type’);

if (!empty($terms) ) {
foreach ( $terms as $term )
echo $term->name;
}
else echo ‘<i>No Location Set. </i>’;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s