get_users_drafts() WordPress Function

The get_users_drafts() function is used to retrieve all the drafts for a given user. This function is useful for displaying a list of all the user's drafts, or for allowing the user to edit their drafts.

get_users_drafts( int $user_id ) #

Retrieve the user’s drafts.


Parameters

$user_id

(int)(Required)User ID.


Top ↑

Return

(array)


Top ↑

Source

File: wp-admin/includes/user.php

function get_users_drafts( $user_id ) {
	global $wpdb;
	$query = $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id );

	/**
	 * Filters the user's drafts query string.
	 *
	 * @since 2.0.0
	 *
	 * @param string $query The user's drafts query string.
	 */
	$query = apply_filters( 'get_users_drafts', $query );
	return $wpdb->get_results( $query );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.