Description
This function is used to get a list of all the posts that are defined in the blog. For the most part get_posts can be considered a mini version of query_posts, supporting nearly (but not all) optional parameters. Support parameters are listed below.
Usage
<?php get_posts( $args ); ?>
Default Usage
<?php $args = array(
'post_type' => 'any',
'post_status' => 'publish',
'post_parent' => $post->ID,
'post_mime_type' => ,
'post__in' => ,
'post__not_in' => ,
'order' => 'DESC',
'orderby' => ,
'author' => ,
'author_name' => ,
'w' => ,
'm' => ,
'month' => ,
'year' => ,
'y' => ,
'meta_key' => ,
'meta_value' => ,
'cat' => ,
'category__in' => ,
'category__not_in' => ,
'category__and' => ,
'tag__in' => ,
'tag__not_in' => ,
'tag__and' => ,
'tag_slug__in' => ,
'tag_slug__and' => ,
'hour' => ,
'minute' => ,
'second' => ,
'suppress_filters' => 0,
'caller_get_posts' => 0,
'offset' => 0 ); ?>
Parameters
Post parameters
- post_type
- (string) Set the type of post type to retrieve(can be used for pages). The default is any. Valid values:
- 'any' - Both posts and pages (Default).
- 'posts' - Select posts, not pages.
- 'pages' - Select pages, not posts.
- post_status
- (string) Select entries with the following status. The default is publish. Valid values:
- 'publish' - Published posts or pages (Default).
- 'inherit' - Attachments.
- 'private' - Private entries.
- post_parent
- (integer) Grab entries associated with this parent ID. The default is 0. Valid values:
- 0 - None (Default).
- ID - Provide an ID.
- post_mime_type
- (string) Select posts/pages based on mime type. Example values:
- - None (Default).
- 'image' - Example: Grab entries with image mime type.
- post__in
- (array) An array of post IDs to select posts or pages from. Valid values:
- post__not_in
- (array) An array of IDs to exclude from the results. Valid values:
Order parameters
- order
- (string) Which order to display the results. Valid values:
- orderby
- (array) Sort results by this value. Valid values:
- 'date' - Order by post date (Default).
- 'author' - Order by author.
- 'title' - Order by title.
- 'modified' - Order by modified date.
- 'menu_order' - Order by menu order (??).
- 'parent' - Order by parent.
- 'ID' - Order by ID.
- 'rand' - Random order.
- offset
- (integer) Offset the query.
Return
- (Array)
- An array containing all the posts matching the request
Source File
get_posts() is located in wp-includes/query.php
.
Related
This article is a
ROUGH DRAFT. The author is still working on this document, so
please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.