My Recent Posts Widget
Gives each writer a dashboard widget with their own latest posts in any status, so they can pick up where they left off.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_my_posts', 'My Recent Posts', function () {
$posts = get_posts( array(
'author' => get_current_user_id(),
'post_type' => 'any',
'post_status' => array( 'publish', 'draft', 'pending', 'future', 'private' ),
'numberposts' => 8,
'orderby' => 'modified',
) );
if ( ! $posts ) {
printf( '<p>You have not written anything yet. <a href="%s">Start a post</a>.</p>', esc_url( admin_url( 'post-new.php' ) ) );
return;
}
$statuses = get_post_statuses();
echo '<ul>';
foreach ( $posts as $item ) {
printf(
'<li><a href="%1$s">%2$s</a> <span class="post-state">— %3$s</span></li>',
esc_url( get_edit_post_link( $item->ID ) ),
esc_html( get_the_title( $item ) ? get_the_title( $item ) : '(no title)' ),
esc_html( isset( $statuses[ $item->post_status ] ) ? $statuses[ $item->post_status ] : $item->post_status )
);
}
echo '</ul>';
} );
} );
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.