Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a code sample that works with get_posts but I now need do with get_pages so I can get grandchildren in the results set:

$attachments = get_posts( array(
        'post_type' => 'attachment'
        ) );

    if ( $attachments ) {
        foreach ( $attachments as $attachment ) {
            $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
            $thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail', true );

            echo '<dl class="' . $class . ' gallery-item masonry-brick">    <dt class="gallery-icon">' . $thumbimg . '</dt></dl>';


When I substitute get_posts with get_pages (all else the same) there are no results. Does anyone know what I'm doing wrong or why this should be?



share|improve this question
Have you tried get_posts() with 'post_type' => 'page'? – toscho Apr 20 '13 at 13:53
I hadn't but I was looking to build a gallery - should I use page? – Steve Apr 20 '13 at 14:59
I am not sure what want: attachments or pages? – toscho Apr 20 '13 at 15:01
hmmm - i want to display a gallery of attachments and it's children/granchildren – Steve Apr 20 '13 at 15:08
galleries are not (yet) post types, and attachments are not a hierarchical post type. Both cannot have children, and get_pages() returns always FALSE for non-hierarchical post types. Try to explain your goal better – in your question, not in a comment, please. :) – toscho Apr 20 '13 at 15:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.