Tagged: 

Viewing 14 reply threads
  • Author
    Posts
    • #4348
      Web Guy
      Member

      I 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!

    • #4349
      Steve
      Keymaster

      You can definitely do this. Check out the built in demos. You’ll find an example there.

    • #4350
      Web Guy
      Member

      In 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?

    • #4351
      Steve
      Keymaster

      Just 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.

    • #4359
      Web Guy
      Member

      Steve

      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’
      )
      ));

    • #4361
      Kevin
      Keymaster

      @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

    • #4365
      Web Guy
      Member

      Thanks! I’ll let you know how it works!

    • #4370
      Web Guy
      Member

      So 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!

    • #4373
      Web Guy
      Member

      MY BAD! Attached images already work just like I want them to. Piklist is AMAZING!

    • #4374
      Steve
      Keymaster

      Nice! Glad you love Piklist. If you have a few minutes, a quick 5 Star Review on WordPress.org really helps the project.

    • #4393
      Web Guy
      Member

      Noticing 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?

    • #4395
      Web Guy
      Member

      Added validate code (below) and still can only add 5 attachements…

      'validate' => array(
            array(
              'type' => 'limit'
              ,'options' => array(
                'min' => 0
                ,'max' => 10
              )
            )
          )
    • #4398
      Steve
      Keymaster

      @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.

    • #4403
      Web Guy
      Member

      Getting there! No longer limited to 5 images.

      Thanks!

    • #4405
      Steve
      Keymaster

      Great! Let us know if you need any more help.

Viewing 14 reply threads
  • You must be logged in to reply to this topic.