# 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.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard, widget, authors
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/my-recent-posts-dashboard-widget/

## Code

```php
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">&mdash; %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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "My Recent Posts Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
