Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created July 16, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bueltge/3121676 to your computer and use it in GitHub Desktop.
Save bueltge/3121676 to your computer and use it in GitHub Desktop.
Filter WordPress date on tables in backend
// my custom field for the author is meta_key
// the field for table, filtering is my_author
$my_post_type = 'post';
add_filter( 'manage_edit-' . $my_post_type . '_columns', 'fb_add_columns' );
add_filter( 'manage_posts_custom_column', 'fb_return_custom_columns', 10, 3 );
add_filter( 'manage_edit-' . $my_post_type . '_sortable_columns', 'fb_sortable_columns' );
function fb_add_columns( $columns ) {
// add id list
$columns['my_author'] = __( 'My Author' );
return $columns;
}
function fb_return_custom_columns( $column_name, $post_id ) {
switch( $column_name ) {
case 'my_author':
$value = get_post_meta($post_id, 'meta_key', TRUE);
break;
}
if ( isset( $value) )
echo $value;
}
function fb_sortable_columns( $columns ) {
$custom = array(
// meta column id => sortby value used in query
'my_author' => 'my_author',
);
return wp_parse_args( $custom, $columns );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment