Tagged: attachments
- This topic has 14 replies, 3 voices, and was last updated 6 years, 4 months ago by
Steve.
-
AuthorPosts
-
-
September 17, 2015 at 5:12 pm #4348
Web GuyMemberI have a CPT (“product”) and I need two kinds of multiple images: composed product images and candid product-in-use images. I’ve read your post about “Multiple Featured Images” and see “field-featured-image.php” on GitHub so I assume I can use this approach for the composed product images.
But what about the candid product-in-use images? Was thinking they could simply be attachments. I could use the built-in attachment support, or get some additional control by using using the “Attachments” plugin. But is there something I can do with Piklist to make managing attachments easier? It would be awesome, for example, if I could SEE the attached images on the CPT screen. As you know, attaching images via editor is invisible. And being able to delete an attached image on the CPT screen would be even awesome-r!
Thoughts & advice most welcome!
-
September 17, 2015 at 5:27 pm #4349
-
September 17, 2015 at 8:32 pm #4350
Web GuyMemberIn the upload demo, I see this… “Validation rule set: Upload no more than two files.”
Specifically, I need to upload multiple — more than 2 — “Featured Images” as in…
https://piklist.com/2013/08/01/v0-8-0-beta-2-and-file-upload-field-with-a-surprise-inside/
Looks like there was some issues. Are they resolved?
-
September 17, 2015 at 8:42 pm #4351
SteveKeymasterJust copy the field code and adjust it. You’ll see the example validation rule for 2 uploads. Adjust it or remove. The code is probably 99% what you need.
-
September 18, 2015 at 5:22 pm #4359
Web GuyMemberSteve
So I hope you’re saying I can use the same ‘upload field’ code for both
image attachments, as well as multiple featured images.Citing code on:
https://piklist.com/2013/08/01/v0-8-0-beta-2-and-file-upload-field-with-a-surprise-inside/Attaching images…
piklist(‘field’, array(
‘type’ => ‘file’
,’field’ => ‘upload_media’
,’scope’ => ‘post_meta’
,’label’ => ‘Add File(s)’
,’options’ => array(
‘title’ => ‘Add File(s)’
,’button’ => ‘Add’
)
));Multiple Featured Images
piklist(‘field’, array(
‘type’ => ‘file’
,’field’ => ‘_thumbnail_id’ // changed for thumb
,’scope’ => ‘post_meta’
,’label’ => ‘Add File(s)’
,’options’ => array(
‘title’ => ‘Add File(s)’
,’button’ => ‘Add’
)
)); -
September 18, 2015 at 7:42 pm #4361
KevinKeymaster@WebGuy-
Looks good to me, however scope is usually unnecessary. For example, if you are creating a post-meta field in a file in meta-boxes then the scope of post_meta is assumed. Let us know how it goes.
Thanks,
Kevin
-
September 19, 2015 at 8:40 am #4365
Web GuyMemberThanks! I’ll let you know how it works!
-
September 20, 2015 at 6:25 pm #4370
Web GuyMemberSo far, so good!
I can upload multiple Featured Images and attach images to my CPT.
How can I display the attached images in the admin? I see code for
displaying them in the fronted, but that won’t work in admin, right?In addition to displaying the attached images, any way to delete them
individually like with Featured Images?Featured Images work SO well, attached ones are jealous!
-
September 21, 2015 at 11:45 am #4373
Web GuyMemberMY BAD! Attached images already work just like I want them to. Piklist is AMAZING!
-
September 21, 2015 at 2:41 pm #4374
SteveKeymasterNice! Glad you love Piklist. If you have a few minutes, a quick 5 Star Review on WordPress.org really helps the project.
-
September 25, 2015 at 3:25 pm #4393
Web GuyMemberNoticing some weird behavior using ‘upload media’ as follows…
piklist('field', array( 'type' => 'file' ,'field' => 'upload_media' ,'scope' => 'post_meta' ,'label' => __('Add \'In The News\' Images','products') ,'options' => array( 'modal_title' => __('Add File(s)','products') ,'button' => __('Add','products') ) ));The images appear and can be managed in the admin, but when I try to display them I can only get five to populate using this code…
<?php if ( $post->post_type == 'products' && $post->post_status == 'publish' ) { $attachments = get_posts( array( 'post_type' => 'attachment', 'exclude' => get_post_meta($post->ID, '_thumbnail_id', false ) ) ); if ( $attachments ) { foreach ( $attachments as $attachment ) { $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type ); $thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true ); echo '<li style="display:inline" class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>'; } } } ?>Also, it seems that I can’t use the Add button in the upload field to attach existing images from the media library. I have to actually upload them. Is this normal?
-
September 25, 2015 at 6:00 pm #4395
Web GuyMemberAdded validate code (below) and still can only add 5 attachements…
'validate' => array( array( 'type' => 'limit' ,'options' => array( 'min' => 0 ,'max' => 10 ) ) ) -
September 28, 2015 at 9:35 am #4398
SteveKeymaster@WebGuy– A few things:
1) You really should prefix your field. Using our default “upload_media” may cause conflicts.
Try:'field' => 'webguy_upload_media'2) Once you upload, try this code. It will show which attachment IDs have been saved:
$media = get_post_meta( $post->ID, 'upload_media', false ); piklist::pre($media);
Let us know what you find.
-
September 28, 2015 at 2:45 pm #4403
Web GuyMemberGetting there! No longer limited to 5 images.
Thanks!
-
September 29, 2015 at 2:33 pm #4405
SteveKeymasterGreat! Let us know if you need any more help.
-
-
AuthorPosts
- You must be logged in to reply to this topic.