0

I am trying to create a metabox to upload multiple files (can be images or files).

Currently I have the upload field and its working file till the time we press upload and saving the data.

The only problem is displaying the files.

Below is my code, I am using to display the metabox:

case 'file_list':
                    echo '<input class="cmb_upload_file" type="text" size="36" name="', $field['id'], '" value="" />';
                    echo '<input class="cmb_upload_button button" type="button" value="Upload File" />';
                    echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
                        $args = array(
                                'post_type' => 'attachment',
                                'numberposts' => null,
                                'post_status' => null,
                                'post_parent' => $post->ID
                            );
                            $attachments = get_posts($args);
                            if ($attachments) {
                                echo '<ul class="attach_list">';
                                foreach ($attachments as $attachment) {
                                    echo '<li>'.wp_get_attachment_link($attachment->ID, 'thumbnail', 0, 0, 'Download');
                                    echo '<span>';
                                    echo apply_filters('the_title', '&nbsp;'.$attachment->post_title);
                                    echo '</span></li>';
                                }
                                echo '</ul>';
                            }
                        break;

1) Currently its displaying me all the files attached to post & I need to display only the files uploaded using this metabox.

2) Need a small thumbnail preview of the file.

Regards.

Himanshu Jain
  • 444
  • 1
  • 8
  • 23

1 Answers1

0

Currently its displaying me all the files attached to post & I need to display only the files uploaded using this metabox.

  • You might need some special field or a way to tell the difference

2) Need a small thumbnail preview of the file

  • attachment-id can obtain you the thumbs by using the get_the_post_thumbnail
teemo
  • 51
  • 2
  • 12