get_users_drafts

Retrieve the user's drafts.

Description

(array) get_users_drafts( (int) $user_id ); 

Returns (array)

Parameters (1)

0. $user_id (int)
The user id.

Usage

  1. if ( !function_exists( 'get_users_drafts' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/user.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_users_drafts($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/user.php  
  1. function get_users_drafts( $user_id ) { 
  2. global $wpdb; 
  3. $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); 
  4.  
  5. /** 
  6. * Filters the user's drafts query string. 
  7. * @since 2.0.0 
  8. * @param string $query The user's drafts query string. 
  9. */ 
  10. $query = apply_filters( 'get_users_drafts', $query ); 
  11. return $wpdb->get_results( $query );