0

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?

Thanks!!!

Steve

6
  • Have you tried get_posts() with 'post_type' => 'page'?
    – fuxia
    Apr 20, 2013 at 13:53
  • I hadn't but I was looking to build a gallery - should I use page?
    – Steve
    Apr 20, 2013 at 14:59
  • I am not sure what want: attachments or pages?
    – fuxia
    Apr 20, 2013 at 15:01
  • hmmm - i want to display a gallery of attachments and it's children/granchildren
    – Steve
    Apr 20, 2013 at 15:08
  • 1
    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. :)
    – fuxia
    Apr 20, 2013 at 15:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.