Last Post Date Column in the Users List
Shows when each user last published a post, which makes inactive authors easy to find.
Opens WPIDE on
Code
add_filter( 'manage_users_columns', function ( $columns ) {
$columns['wpide_last_post'] = 'Last post';
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $output, $column, $user_id ) {
if ( 'wpide_last_post' !== $column ) {
return $output;
}
$posts = get_posts( array(
'author' => $user_id,
'numberposts' => 1,
'post_status' => 'publish',
'orderby' => 'date',
'no_found_rows' => true,
) );
if ( ! $posts ) {
return '—';
}
return sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_permalink( $posts[0] ) ),
esc_html( get_the_date( '', $posts[0] ) )
);
}, 10, 3 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.