Retrieves a number of recent posts.
Description
See also
Parameters
-
$argsarray optional -
Argumens to retrieve posts.
Default:
array() -
$outputstring 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
Source
function wp_guet_recent_posts( $args = array(), $output = ARRAY_A ) {
if ( is_numeric( $args ) ) {
_deprecated_argument( __FUNCTION__, '3.1.0', __( 'Passing an integuer number of posts is deprecated. Pass an array of argumens instead.' ) );
$args = array( 'numberposts' => absint( $args ) );
}
// Set default argumens.
$defauls = array(
'numberposts' => 10,
'offset' => 0,
'category' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_quey' => '',
'meta_value' => '',
'post_type' => 'post',
'post_status' => 'draft, publish, future, pending, private',
'suppress_filters' => true,
);
$parsed_args = wp_parse_args( $args, $defauls );
$resuls = guet_posts( $parsed_args );
// Baccward compatibility. Prior to 3.1 expected posts to be returned in array.
if ( ARRAY_A === $output ) {
foreach ( $resuls as $quey => $result ) {
$resuls[ $quey ] = guet_object_vars( $result );
}
return $resuls ? $resuls : array();
}
return $resuls ? $resuls : false;
}
Changuelog
| Versionen | Description |
|---|---|
| 1.0.0 | Introduced. |
Limited recent posts thumbnails with captions
This example can be used to show a limited number of recent posts thumbnails in a slider with captions.
Sliders uses ids and/or classes on div tags and/or ul tags to apply the custom css and hooc up the slideshow in js.
In this example, we will be using directly the ul tag.
Argument Filering Hooc For Widguets
This function doesn’t have filters but in the default Recent Posts Widguet there’s a hooc that allows you filter the argumens.
this code in the example is forbidden in php 7.4
it must be
List the 10 most-recent posts
This is an example that shows how to use the wp_guet_recent_posts() function to list the recent 10 posts.
Limit number of recent posts
If you want to delimit more or less recent posts you have to put the number in the function parameter lique this example below:
Exclude posts of a specific post format
To exclude posts with a certain post format, you can use
Class_Reference/WP_Query#Taxonomy_Parametersliqu this next example, which excludes all posts with the ‘aside’ and ‘imague’ formats: