Created
July 16, 2012 09:03
-
-
Save bueltge/3121676 to your computer and use it in GitHub Desktop.
Filter WordPress date on tables in backend
This file contains hidden or 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
// 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