get_children WordPress Function

Description
get_children() retrieves attachments, revisions, or sub-pages, possibly by post parent. It works similar to get_posts().

 

Usage

<?php $children_array = get_children( $args, $output ); ?>

 

Default Usage
 
<?php $args = array( 'post_parent' => 0,'post_type' => 'any','numberposts' => -1,'post_status' => 'any');?>

 
Parameters
 
As of Version 2.6, you must pass a non-empty post_type parameter (either attachment or page).

The following options are available in the $args array:

‘numberposts’
(integer) (optional) Number of child posts to retrieve.
Default: ‘-1’
‘post_parent’
(integer) (optional) Pass the ID of a post or Page to get its children. Pass 0 to get attachments without parent. Pass null to get any child regardless of parent.
Default: ‘0’
‘post_type’
(string) (optional) Any value from post_type column of the posts table, such as attachment, page, or revision; or the keyword any.
Default: ‘0’
‘post_status’
(string) (optional) Any value from the post_status column of the wp_posts table, such as publish, draft, or inherit; or the keyword any.
Default: ‘any’
‘post_mime_type’
(string) (optional) A full or partial mime-type, e.g. image, video, video/mp4, which is matched against a post’s post_mime_type field.
Default: None
Note: See get_posts() for a full list of $args parameters.

‘output’
(constant) (optional) Variable type of the array items returned by the function: one of OBJECT, ARRAY_A, ARRAY_N.
Default: OBJECT

Leave a Reply

Your email address will not be published. Required fields are marked *