get_children WordPress Function

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



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


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

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:

(integer) (optional) Number of child posts to retrieve.
Default: ‘-1’
(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’
(string) (optional) Any value from post_type column of the posts table, such as attachment, page, or revision; or the keyword any.
Default: ‘0’
(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’
(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.

(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 *