wp_get_recent_posts

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

WordPress Version: 6.1

/**
 * Retrieves a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args   Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which
 *                       correspond to a WP_Post object or an associative array, respectively.
 *                       Default ARRAY_A.
 * @return array|false Array of recent posts, where the type of each element is determined
 *                     by the `$output` parameter. Empty array on failure.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    $results = get_posts($parsed_args);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A === $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 5.8

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args   Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which
 *                       correspond to a WP_Post object or an associative array, respectively.
 *                       Default ARRAY_A.
 * @return array|false Array of recent posts, where the type of each element is determined
 *                     by the `$output` parameter. Empty array on failure.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    $results = get_posts($parsed_args);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A === $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 5.5

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args   Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which
 *                       correspond to a WP_Post object or an associative array, respectively.
 *                       Default ARRAY_A.
 * @return array|false Array of recent posts, where the type of each element is determined
 *                     by the `$output` parameter. Empty array on failure.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    $results = get_posts($parsed_args);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 5.3

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args   Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which correspond to
 *                       a WP_Post object or an associative array, respectively. Default ARRAY_A.
 * @return array|false Array of recent posts, where the type of each element is determined by $output parameter.
 *                     Empty array on failure.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    $results = get_posts($parsed_args);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 4.7

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args   Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output Optional. The required return type. One of OBJECT or ARRAY_A, which correspond to
 *                       a WP_Post object or an associative array, respectively. Default ARRAY_A.
 * @return array|false Array of recent posts, where the type of each element is determined by $output parameter.
 *                     Empty array on failure.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 4.6

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args       Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output     Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
 * @return array|false Associative array if $output equals ARRAY_A, array or false if no results.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1.0', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 4.3

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args       Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output     Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
 * @return array|false Associative array if $output equals ARRAY_A, array or false if no results.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 4.1

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param array  $args       Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output     Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
 * @return array|bool Associative array if $output equals ARRAY_A, array or false if no results.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 4.0

/**
 * Retrieve a number of recent posts.
 *
 * @since 1.0.0
 *
 * @see get_posts()
 *
 * @param string $deprecated Not used.
 * @param array  $args       Optional. Arguments to retrieve posts. Default empty array.
 * @param string $output     Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
 * @return array|bool Associative array if $output equals ARRAY_A, array or false if no results.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments.
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array.
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}

WordPress Version: 3.7

/**
 * Retrieve number of recent posts.
 *
 * @since 1.0.0
 * @uses wp_parse_args()
 * @uses get_posts()
 *
 * @param string $deprecated Deprecated.
 * @param array $args Optional. Overrides defaults.
 * @param string $output Optional.
 * @return unknown.
 */
function wp_get_recent_posts($args = array(), $output = ARRAY_A)
{
    if (is_numeric($args)) {
        _deprecated_argument(__FUNCTION__, '3.1', __('Passing an integer number of posts is deprecated. Pass an array of arguments instead.'));
        $args = array('numberposts' => absint($args));
    }
    // Set default arguments
    $defaults = array('numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true);
    $r = wp_parse_args($args, $defaults);
    $results = get_posts($r);
    // Backward compatibility. Prior to 3.1 expected posts to be returned in array
    if (ARRAY_A == $output) {
        foreach ($results as $key => $result) {
            $results[$key] = get_object_vars($result);
        }
        return $results ? $results : array();
    }
    return $results ? $results : false;
}