Wordpress custom column page
Have you ever wanted to show your meta data (custom fields) directly in the page / post listing?
Here is a very simple tutorial with how you easliy add a custom column in your page listing with your own meta data - With a sorting function.
The code
add_filter('manage_pages_columns', 'my_columns', 3); function my_columns($columns) { // When and how the order should be if.. $order = 'asc'; if($_GET['order'] == 'asc') { $order = 'desc'; } else { $order = 'asc'; } // The columns - With links to be able to sort. $columns['column_1'] = '<a href="edit.php?post_type=page&orderby=column_1&order='. $order .'">Column_1'; $columns['column_2'] = '<a href="edit.php?post_type=page&orderby=column_2&order='. $order .'">Column_2'; // Example how to unset standard columns. unset($columns['comments']); unset($columns['author']); // Return the column return $columns; } // Lets fill the columns in hand. add_action('manage_pages_custom_column', 'my_show_columns'); function my_show_columns($name) { global $post; switch ($name) { case 'column_1': $column_1 = get_post_meta($post->ID, 'your-meta-1', true); echo $column_1; break; case 'column_2': $column_2 = get_post_meta($post->ID, 'your-meta-2', true); echo $column_2; break; } }



















