Ok, so this works for me when inserted into my “functions.php” file in my theme. To clarify, I called my editorial metadata “Working on”, and gave it a type of “user.” That’s why I’m looking for a post_meta called “_ef_editorial_meta_user_working-on”. The “_ef_editorial_meta” is prepended for editorial metadata as post meta being inserted into the database. The “_user” is another string prepended because I selected a type of “user”, and then “working-on” is just the name of my editorial meta data (uncapitalized and spaces replaced with dashes Ninja Edit: It might actually be the slug that’s being appended, not just the name decapitalized and dashes removed. I’ll double check). To double check, just save a post with the meta data of your choice and look at the database to see how it’s been saved. But is should save along the lines of the formula above.
I could not for the life of me figure out where the sortable_columns filter is applied. I’m still trying to hunt it down just cause I’m curious, but it works at making it sortable. I called my column “Editor,” which you’ll see in the add_editor_columns function.
Feel free to post back here if you’re having problems or if the code needs more ‘splainin.
// Getting metadata to show up on posts table
add_action( 'manage_posts_custom_column' , 'ef_custom_column', 10, 2 );
function ef_custom_column($column, $post_id) {
if( $column == 'editor' ) {
$user_id = (int)get_post_meta($post_id, '_ef_editorial_meta_user_working-on', true );
$editor = get_user_by('id', $user_id);
echo $editor->user_nicename;
}
}
add_filter('manage_post_posts_columns' , 'add_editor_columns');
function add_editor_columns($columns) {
return array_merge($columns,
array('editor' => __('Editor')));
}
add_filter( 'manage_edit-post_sortable_columns', 'make_editor_sortable' );
function make_editor_sortable($columns) {
$columns['editor'] = 'editor';
return $columns;
}