plugins - multiple image upload using wp_enqueue_media

I have created a custom plugin and there has an image upload option.In view page:<div class="form-group">

I have created a custom plugin and there has an image upload option.

In view page:
<div class="form-group"> <label class="control-label col-sm-2">Trade Photo:</label> <div class="col-sm-10"> <input type="button" class="btn btn-info" id="t_photo" value="Upload Photo" required> <span id="show-image"></span> <input type="hidden" id="trade_pic" name="trade_pic"> </div> </div>

And is js area:

   var image = wp.media.frames.file_frame = wp.media({
        title: 'Upload Image for Trade Details',
        button: {
          text: 'Choose Image'
        },
        multiple: true
      });
      image.on('select', function() {
        var selection = image.state().get('selection');
        selection.map( function( getImage ) {
            getImage = getImage.toJSON();
            jQuery("#show-image").after("<img src=" +getImage.url+" style='height:50px;width:50px;'/>");
            jQuery("#trade_pic").val(getImage.url);
        });
      });
      image.open();

How to upload multiple images using this method? I got all images but in value, it returns only the first image? How to get all images URL with separated (,)

I have created a custom plugin and there has an image upload option.

In view page:
<div class="form-group"> <label class="control-label col-sm-2">Trade Photo:</label> <div class="col-sm-10"> <input type="button" class="btn btn-info" id="t_photo" value="Upload Photo" required> <span id="show-image"></span> <input type="hidden" id="trade_pic" name="trade_pic"> </div> </div>

And is js area:

   var image = wp.media.frames.file_frame = wp.media({
        title: 'Upload Image for Trade Details',
        button: {
          text: 'Choose Image'
        },
        multiple: true
      });
      image.on('select', function() {
        var selection = image.state().get('selection');
        selection.map( function( getImage ) {
            getImage = getImage.toJSON();
            jQuery("#show-image").after("<img src=" +getImage.url+" style='height:50px;width:50px;'/>");
            jQuery("#trade_pic").val(getImage.url);
        });
      });
      image.open();

How to upload multiple images using this method? I got all images but in value, it returns only the first image? How to get all images URL with separated (,)

Share Improve this question edited Apr 28, 2019 at 10:22 asked Apr 28, 2019 at 7:37 user155636user155636
Add a comment  | 

1 Answer 1

Reset to default 0

I solved it here is my code:

      image.on('select', function() {
        let selection = image.state().get('selection');

        let _getImage = [];

        selection.map( function( getImage ) {
            _getImage.push(getImage.toJSON())

            getImage = getImage.toJSON();

            jQuery("#show-image").after("<img src=" +getImage.url+" style='height:50px;width:50px;'/>");

        })

        jQuery("#trade_pic").after("<input type='hidden' name='trade_pic' value='"+_getImage.map(val=> val.url)+"'/>")

      });

      image.open();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745544295a4632269.html

相关推荐

  • plugins - multiple image upload using wp_enqueue_media

    I have created a custom plugin and there has an image upload option.In view page:<div class="form-group">

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信