Advertisements

wp_get_recent_posts

Definition:
function wp_get_recent_posts( $args = array() {}

Retrieve number of recent posts.

Parameters

  • string $deprecated: Deprecated.
  • array $args: Optional. Overrides defaults.
  • string $output: Optional.

Source code

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;



}

3741

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: