WordPress.org

Ready to get started?Download WordPress

Forums

Previously uploaded attachments is not showing (1 post)

  1. tanvir
    Member
    Posted 1 year ago #

    I'm trying to get all attachment of a post in one place and apply the following code from codex. But it's returning only the newly uploaded attachments not the attachments inserted from media library.

    $args = array(
                    'post_type' => 'attachment',
                    'numberposts' => -1,
                    'post_status' => null,
                    'post_parent' => $post->ID
                );
    
                $attachments = get_posts( $args );
         if ( $attachments ) {
             echo '<ul>';
             foreach ( $attachments as $attachment ) {
                 echo '<li>';
                 //echo wp_get_attachment_image( $attachment->ID, 'page-img' );
                 echo $attachment->ID;
                 echo '</li>';
             }
             echo '</ul>';
         }

    Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic