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 fine until the time we press upload and save 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', ' '.$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.
question 1
Im not sure how you can do that, But you could try add the image link, and the file path as a meta_post and get the values from there, when you get the values you will only get the files/images from that post uploaded from that metabox.
You can also try custom-fields-to-attachments where you add an ID to only query the files you uploaded from that metabox.
question 2
this code could work.