• Greetings. I’m trying to retrieve attachment urls to the post being added/edited in the visual text editor, using a pop-up window similar to the Add Media window, from within my theme. However, the code I’ve hacked together lists all files of the attachment type in the Media Library rather than just those for the post. How to I get only files for the post being worked with? This is the code that lists mp4s:

    function mp4s(){
        global $post;
        $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'video/mp4', 'post_status' => null, 'post_parent' => $post->ID );
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ( $attachments as $attachment ) {
                        $src = wp_get_attachment_url( $attachment->ID);
                        if ($src) {echo '<option>'.$src.'</option>';}
                }
        }
    }

    This shows only attachments for the post if I use it in a meta box in the admin, but not in the pop-up accessed via an icon I’ve added to the visual editor through the theme’s functions.php.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Retrieving post attachments’ is closed to new replies.