Title: wp_dashboard_recent_drafts
Published: April 25, 2014
Last modified: April 28, 2025

---

# wp_dashboard_recent_drafts( WP_Post[]|false $drafts = false )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#wp--skip-link--target)

Show recent drafts of the user on the dashboard.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#parameters)󠁿

 `$drafts`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)[]
|falseoptional

Array of posts to display.

Default:`false`

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#source)󠁿

    ```php
    function wp_dashboard_recent_drafts( $drafts = false ) {
    	if ( ! $drafts ) {
    		$query_args = array(
    			'post_type'      => 'post',
    			'post_status'    => 'draft',
    			'author'         => get_current_user_id(),
    			'posts_per_page' => 4,
    			'orderby'        => 'modified',
    			'order'          => 'DESC',
    		);

    		/**
    		 * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
    		 *
    		 * @since 4.4.0
    		 *
    		 * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
    		 */
    		$query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );

    		$drafts = get_posts( $query_args );
    		if ( ! $drafts ) {
    			return;
    		}
    	}

    	echo '<div class="drafts">';

    	if ( count( $drafts ) > 3 ) {
    		printf(
    			'<p class="view-all"><a href="%s">%s</a></p>' . "\n",
    			esc_url( admin_url( 'edit.php?post_status=draft' ) ),
    			__( 'View all drafts' )
    		);
    	}

    	echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n";
    	echo '<ul>';

    	/* translators: Maximum number of words used in a preview of a draft on the dashboard. */
    	$draft_length = (int) _x( '10', 'draft_length' );

    	$drafts = array_slice( $drafts, 0, 3 );
    	foreach ( $drafts as $draft ) {
    		$url   = get_edit_post_link( $draft->ID );
    		$title = _draft_or_post_title( $draft->ID );

    		echo "<li>\n";
    		printf(
    			'<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
    			esc_url( $url ),
    			/* translators: %s: Post title. */
    			esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
    			esc_html( $title ),
    			get_the_time( 'c', $draft ),
    			get_the_time( __( 'F j, Y' ), $draft )
    		);

    		$the_content = wp_trim_words( $draft->post_content, $draft_length );

    		if ( $the_content ) {
    			echo '<p>' . $the_content . '</p>';
    		}
    		echo "</li>\n";
    	}

    	echo "</ul>\n";
    	echo '</div>';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/dashboard.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/dashboard.php#L623)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/dashboard.php#L623-L691)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#hooks)󠁿

 [apply_filters( ‘dashboard_recent_drafts_query_args’, array $query_args )](https://developer.wordpress.org/reference/hooks/dashboard_recent_drafts_query_args/)

Filters the post query arguments for the ‘Recent Drafts’ dashboard widget.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#related)󠁿

| Uses | Description | 
| [_draft_or_post_title()](https://developer.wordpress.org/reference/functions/_draft_or_post_title/)`wp-admin/includes/template.php` |

Gets the post title.

  | 
| [wp_trim_words()](https://developer.wordpress.org/reference/functions/wp_trim_words/)`wp-includes/formatting.php` |

Trims text to a certain number of words.

  | 
| [get_the_time()](https://developer.wordpress.org/reference/functions/get_the_time/)`wp-includes/general-template.php` |

Retrieves the time of the post.

  | 
| [get_edit_post_link()](https://developer.wordpress.org/reference/functions/get_edit_post_link/)`wp-includes/link-template.php` |

Retrieves the edit post link for post.

  | 
| [get_posts()](https://developer.wordpress.org/reference/functions/get_posts/)`wp-includes/post.php` |

Retrieves an array of the latest posts, or posts matching the given criteria.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_x()](https://developer.wordpress.org/reference/functions/_x/)`wp-includes/l10n.php` |

Retrieves translated string with gettext context.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [admin_url()](https://developer.wordpress.org/reference/functions/admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current site.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_current_user_id()](https://developer.wordpress.org/reference/functions/get_current_user_id/)`wp-includes/user.php` |

Gets the current user’s ID.

  |

[Show 8 more](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#)

| Used by | Description | 
| [wp_dashboard_quick_press()](https://developer.wordpress.org/reference/functions/wp_dashboard_quick_press/)`wp-admin/includes/dashboard.php` |

Displays the Quick Draft widget.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_dashboard_recent_drafts/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dashboard_recent_drafts%2F)
before being able to contribute a note or feedback.