wp_get_recent_posts() – Retrieve a number of recent posts.

You appear to be a bot. Output may be restricted

Description

Retrieve a number of recent posts.

Usage

$array|false = wp_get_recent_posts( $args, $output );

Parameters

$args
( array ) optional – Optional. Arguments to retrieve posts. Default empty array.
$output
( string ) optional default: ARRAY_A – 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.

Returns

array|false Array of recent posts, where the type of each element is determined by the $output parameter. Empty array on failure.

Source

File name: wordpress/wp-includes/post.php
Lines:

1 to 38 of 38
function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {

  if ( is_numeric( $args ) ) {
    _deprecated_argument( wp_get_recent_posts, '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;

}
 

 View on GitHub View on Trac