Skip to content

Instantly share code, notes, and snippets.

@kristianb21
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristianb21/93f77d84247d9a06ef0e to your computer and use it in GitHub Desktop.
Save kristianb21/93f77d84247d9a06ef0e to your computer and use it in GitHub Desktop.
PHP:WP-get children
<?php
//get_children()
$args = array(
// number of post to retrieve
'numberposts' => -1,
/*
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.
*/
'post_parent' => $post->ID,
/*
Any value from post_type column of the posts table,
such as attachment, page, or revision; or the keyword
*/
'post_type' => 'any',
/*
Any value from the post_status column of the wp_posts table,
such as publish, draft, or inherit; or the keyword any.
*/
'posts_per_page' => -1,
'post_status' => 'any',
'output' => OBJECT
/*
Variable type of the array items returned by the function: one of OBJECT, ARRAY_A, ARRAY_N.
Default: OBJECT
*/
);
$output = OBJECT;
$children_array = get_children( $args, $output );?>
<pre><?php print_r($children_array);?></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment