Last active
June 3, 2020 09:49
-
-
Save acolson/c1e58f9dab6bc070ac81 to your computer and use it in GitHub Desktop.
WordPress sortable custom admin column for last modified date and user
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_filter( 'manage_edit-post_columns', 'aco_last_modified_admin_column' ); | |
// Create the last modified column | |
function aco_last_modified_admin_column( $columns ) { | |
$columns['modified-last'] =__( 'Last Modified', 'aco' ); | |
return $columns; | |
} | |
add_filter( 'manage_edit-post_sortable_columns', 'aco_sortable_last_modified_column' ); | |
// Allow that content to be sortable by modified time information | |
function aco_sortable_last_modified_column( $columns ) { | |
$columns['modified-last'] = 'modified'; | |
return $columns; | |
} | |
add_action( 'manage_posts_custom_column', 'aco_last_modified_admin_column_content', 10, 2 ); | |
// Format the output | |
function aco_last_modified_admin_column_content( $column_name, $post_id ) { | |
// Do not continue if this is not the modified column | |
if ( 'modified-last' != $column_name ) | |
return; | |
$modified_date = the_modified_date( 'Y/m/d - g:i A' ); | |
$modified_author = get_the_modified_author(); | |
echo $modified_date; | |
echo '<br>'; | |
echo '<strong>' . $modified_author . '</strong>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this doesn't appear to show the last modified user, but rather the post/page author?