How would I retrieve attachments from all subpages of a particular Web page ID?
Instance:
SPECIFIC PAGE
- Youngster (with attachments)
- Youngster (with attachments)
- Youngster (with attachments)
I am at the moment utilizing this code to retrieve all attachments site-wide, nevertheless I wish to restrict this to solely pull pictures from all kids of a particular Web page.
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => null
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $publish ) {
setup_postdata( $publish );
the_title();
the_attachment_link( $post->ID, false );
the_excerpt();
}
}
Nearly there utilizing this code under:
$mypages = get_pages( 'child_of=19' );
foreach ( $mypages as $mypage ) {
$attachments = get_children( array(
'post_parent' => $mypage->ID,
'numberposts' => 1,
'post_type' => 'attachment',
'post_mime_type' => 'picture',
'orderby' => 'rand'
) );
if ( $attachments ) {
foreach ( $attachments as $publish ) {
setup_postdata($publish);
the_title();
the_attachment_link( $post->ID, false );
the_excerpt();
}
}
}
Nevertheless, there are two remaining points:
- Limiting the quantity of whole images pulled. Utilizing
'numberposts'
solely limits the quantity of pictures pulled from every publish. - Randomization.
Orderby => rand
solely randomizes the pictures inside every publish. I wish to randomly shuffle the order for every thing.