Codex tools: Log in / create account
get_children() retrieves attachments, revisions, or sub-Pages, possibly by post parent.
It works similarly to get_posts().
Contents |
array|false $children =& get_children( mixed $args = "", constant $output = OBJECT);
Returns an associative array of posts (of variable type set by `$output` parameter) with post IDs as array keys, or false if no posts are found.
If you just want to get or display attachments, it's probably a little easier to use get_posts() instead.
$images =& get_children( 'post_type=attachment&post_mime_type=image' );
$videos =& get_children( 'post_type=attachment&post_mime_type=video/mp4' );
if ( empty($images) ) {
// no attachments here
} else {
foreach ( $images as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'full' );
}
}
// If you don't need to handle an empty result:
foreach ( (array) $videos as $attachment_id => $attachment ) {
echo wp_get_attachment_link( $attachment_id );
}
$defaults = array(
'post_parent' => 0,
'post_type' => 'any',
'numberposts' => -1,
'post_status' => 'any',
);
See get_posts() for a full list of parameters.
As of Version 2.6, you must pass a non-empty post_type parameter (either attachment or page).
get_children() calls get_posts(), which calls $WP_Query->get_posts().