Created
June 17, 2013 15:07
-
-
Save cameronbaney/5797613 to your computer and use it in GitHub Desktop.
List meta keys in the dashboard of custom post types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add custom column to the Papers area | |
add_filter('manage_edit-[POST-TYPE]_columns', 'custom_papers_cols'); | |
function custom_papers_cols($gallery_columns) { | |
$new_columns['cb'] = '<input type="checkbox" />'; | |
$new_columns['id'] = __('ID'); | |
$new_columns['title'] = _x('Title', 'column name'); | |
$new_columns['papertype'] = __('Paper Type'); | |
$new_columns['author'] = __('University'); | |
$new_columns['email'] = __('Email'); | |
$new_columns['tags'] = __('Tags'); | |
$new_columns['date'] = _x('Date', 'column name'); | |
return $new_columns; | |
} | |
// Add to admin_init function | |
add_action('manage_[POST-TYPE]_posts_custom_column', 'manage_paper_cols', 10, 2); | |
function manage_paper_cols($column_name, $id) { | |
global $wpdb; | |
switch ($column_name) { | |
case 'id': | |
echo $id; | |
break; | |
case 'papertype': | |
$paperType = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = {$id} AND meta_key = 'paper_type'"); | |
echo $paperType; | |
break; | |
default: | |
break; | |
} // end switch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment