get_others_unpublished_posts

The timeline below displays how wordpress function get_others_unpublished_posts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 4.9

/**
 * Retrieves editable posts from other users.
 *
 * @since 2.3.0
 * @deprecated 3.1.0 Use get_posts()
 * @see get_posts()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int    $user_id User ID to not retrieve posts from.
 * @param string $type    Optional. Post type to retrieve. Accepts 'draft', 'pending' or 'any' (all).
 *                        Default 'any'.
 * @return array List of posts from others.
 */
function get_others_unpublished_posts($user_id, $type = 'any')
{
    _deprecated_function(__FUNCTION__, '3.1.0');
    global $wpdb;
    $editable = get_editable_user_ids($user_id);
    if (in_array($type, array('draft', 'pending'))) {
        $type_sql = " post_status = '{$type}' ";
    } else {
        $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
    }
    $dir = ('pending' == $type) ? 'ASC' : 'DESC';
    if (!$editable) {
        $other_unpubs = '';
    } else {
        $editable = join(',', $editable);
        $other_unpubs = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_author FROM {$wpdb->posts} WHERE post_type = 'post' AND {$type_sql} AND post_author IN ({$editable}) AND post_author != %d ORDER BY post_modified {$dir}", $user_id));
    }
    return apply_filters('get_others_drafts', $other_unpubs);
}

WordPress Version: 4.6

/**
 * Retrieves editable posts from other users.
 *
 * @since 2.3.0
 * @deprecated 3.1.0 Use get_posts()
 * @see get_posts()
 *
 * @param int    $user_id User ID to not retrieve posts from.
 * @param string $type    Optional. Post type to retrieve. Accepts 'draft', 'pending' or 'any' (all).
 *                        Default 'any'.
 * @return array List of posts from others.
 */
function get_others_unpublished_posts($user_id, $type = 'any')
{
    _deprecated_function(__FUNCTION__, '3.1.0');
    global $wpdb;
    $editable = get_editable_user_ids($user_id);
    if (in_array($type, array('draft', 'pending'))) {
        $type_sql = " post_status = '{$type}' ";
    } else {
        $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
    }
    $dir = ('pending' == $type) ? 'ASC' : 'DESC';
    if (!$editable) {
        $other_unpubs = '';
    } else {
        $editable = join(',', $editable);
        $other_unpubs = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_author FROM {$wpdb->posts} WHERE post_type = 'post' AND {$type_sql} AND post_author IN ({$editable}) AND post_author != %d ORDER BY post_modified {$dir}", $user_id));
    }
    return apply_filters('get_others_drafts', $other_unpubs);
}

WordPress Version: 4.5

/**
 * Retrieves editable posts from other users.
 *
 * @since 2.3.0
 * @deprecated 3.1.0 Use get_posts()
 * @see get_posts()
 *
 * @param int    $user_id User ID to not retrieve posts from.
 * @param string $type    Optional. Post type to retrieve. Accepts 'draft', 'pending' or 'any' (all).
 *                        Default 'any'.
 * @return array List of posts from others.
 */
function get_others_unpublished_posts($user_id, $type = 'any')
{
    _deprecated_function(__FUNCTION__, '3.1');
    global $wpdb;
    $editable = get_editable_user_ids($user_id);
    if (in_array($type, array('draft', 'pending'))) {
        $type_sql = " post_status = '{$type}' ";
    } else {
        $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
    }
    $dir = ('pending' == $type) ? 'ASC' : 'DESC';
    if (!$editable) {
        $other_unpubs = '';
    } else {
        $editable = join(',', $editable);
        $other_unpubs = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_author FROM {$wpdb->posts} WHERE post_type = 'post' AND {$type_sql} AND post_author IN ({$editable}) AND post_author != %d ORDER BY post_modified {$dir}", $user_id));
    }
    return apply_filters('get_others_drafts', $other_unpubs);
}

WordPress Version: 4.4

/**
 * Retrieve editable posts from other users.
 *
 * @deprecated 3.1.0 Use get_posts()
 * @see get_posts()
 *
 * @param int $user_id User ID to not retrieve posts from.
 * @param string $type Optional, defaults to 'any'. Post type to retrieve, can be 'draft' or 'pending'.
 * @return array List of posts from others.
 */
function get_others_unpublished_posts($user_id, $type = 'any')
{
    _deprecated_function(__FUNCTION__, '3.1');
    global $wpdb;
    $editable = get_editable_user_ids($user_id);
    if (in_array($type, array('draft', 'pending'))) {
        $type_sql = " post_status = '{$type}' ";
    } else {
        $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
    }
    $dir = ('pending' == $type) ? 'ASC' : 'DESC';
    if (!$editable) {
        $other_unpubs = '';
    } else {
        $editable = join(',', $editable);
        $other_unpubs = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_author FROM {$wpdb->posts} WHERE post_type = 'post' AND {$type_sql} AND post_author IN ({$editable}) AND post_author != %d ORDER BY post_modified {$dir}", $user_id));
    }
    return apply_filters('get_others_drafts', $other_unpubs);
}

WordPress Version: 3.7

/**
 * Retrieve editable posts from other users.
 *
 * @deprecated 3.1.0
 *
 * @param int $user_id User ID to not retrieve posts from.
 * @param string $type Optional, defaults to 'any'. Post type to retrieve, can be 'draft' or 'pending'.
 * @return array List of posts from others.
 */
function get_others_unpublished_posts($user_id, $type = 'any')
{
    _deprecated_function(__FUNCTION__, '3.1');
    global $wpdb;
    $editable = get_editable_user_ids($user_id);
    if (in_array($type, array('draft', 'pending'))) {
        $type_sql = " post_status = '{$type}' ";
    } else {
        $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
    }
    $dir = ('pending' == $type) ? 'ASC' : 'DESC';
    if (!$editable) {
        $other_unpubs = '';
    } else {
        $editable = join(',', $editable);
        $other_unpubs = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_author FROM {$wpdb->posts} WHERE post_type = 'post' AND {$type_sql} AND post_author IN ({$editable}) AND post_author != %d ORDER BY post_modified {$dir}", $user_id));
    }
    return apply_filters('get_others_drafts', $other_unpubs);
}