Skip to content

Instantly share code, notes, and snippets.

@acolson
Last active June 3, 2020 09:49
Show Gist options
  • Save acolson/c1e58f9dab6bc070ac81 to your computer and use it in GitHub Desktop.
Save acolson/c1e58f9dab6bc070ac81 to your computer and use it in GitHub Desktop.
WordPress sortable custom admin column for last modified date and user
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>';
}
@CarloMartini
Copy link

@acolson
Is there any way to make it work for all post types, including custom one?

@dave-gil
Copy link

dave-gil commented Jun 3, 2020

+1 This would be really useful to have work on all post types if poss?

@dave-gil
Copy link

dave-gil commented Jun 3, 2020

Note: this doesn't appear to show the last modified user, but rather the post/page author?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment