Skip to content

Instantly share code, notes, and snippets.

@htasirx
Last active January 30, 2020 17:49
Show Gist options
  • Save htasirx/f0ea84d158b535bc223566774577f790 to your computer and use it in GitHub Desktop.
Save htasirx/f0ea84d158b535bc223566774577f790 to your computer and use it in GitHub Desktop.
FUNCTION

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

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

$images = get_children( 'post_type=attachment&post_mime_type=image' );

$videos = get_children( 'post_type=attachment&post_mime_type=video/mp4' );

if ( empty($images) ) {

} else { foreach ( $images as $attachment_id => $attachment ) 
{ echo wp_get_attachment_image( $attachment_id, 'full' ); } }

foreach ( (array) $videos as $attachment_id => $attachment )
{ echo wp_get_attachment_link( $attachment_id ); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment