Site icon CodeGurus

Custom columns for custom post type

When using hook “manage_MY_TYPE_NAME_posts_columns” or “manage_MY_TYPE_NAME_posts_custom_column” on WP version >= 3.1 the syntax is little bit changed.

Here’s the example:

add_filter('manage_MY_TYPE_NAME_posts_custom_column', 'my_column_values');
add_filter('manage_MY_TYPE_NAME_posts_columns', 'my_columns');

function my_columns($columns)
{
	$columns['custom_col'] = __('Field name text');
	return $columns;
}

function my_column_values($name, $post_id)
{
	global $post, $typenow;

	// Use $typenow to check custom post type

	switch ($name)
	{
		case 'custom_col':
			echo 'value';
		break;
	}
}
Exit mobile version