Get value of repeated upload button in the right field

330
January 30, 2017, at 00:00 AM

With the help of other stackoverflow questions+answers I was able to create a WordPress post metabox with repeated media upload fields.

Code for my metabox + saving post meta can be found here: https://gist.github.com/kiarashi/f281575bc344d5459d930cf2ffe51817

With this code here is where I need a bit of help

jQuery(document).ready(function($){
    $('.custom_media_upload').click(function() {
        var send_attachment_bkp = wp.media.editor.send.attachment;
        var button = $(this);
        wp.media.editor.send.attachment = function(props, attachment) {
           $(button).prev().val(attachment.url);
            //$(button).closest('.custom_media_url').val(attachment.url);
            wp.media.editor.send.attachment = send_attachment_bkp;
        }
        wp.media.editor.open(button);
        return false;       
    });

    $('#add-row-image').on('click', function() {
        var row = $('.km-empty-row.screen-reader-text').clone(true);
        row.removeClass('km-empty-row screen-reader-text');
        row.insertBefore('#repeatable-fieldset-two tbody>tr:last');
        return false;
    });

    $('.remove-row').on('click', function() {
        $(this).parents('tr').remove();
        return false;
    });
    $('#repeatable-fieldset-two tbody').sortable({
        opacity: 0.6,
        revert: true,
        cursor: 'move',
        handle: '.sort'
    }); 
});

This is what I'm trying to do.

I tried using $(button).prev().val(attachment.url);and $(button).closest('.custom_media_url').val(attachment.url); but it doesn't quite work.

Any help is much appreciated.

Rent Charter Buses Company
READ ALSO
How to get the index of which element we clicked on

How to get the index of which element we clicked on

I have a list of containers and I want to add a button that display a terminal on the container where we clicked on the terminal logo

325
Can't get data with Handlebars from JSON

Can't get data with Handlebars from JSON

Here is fiddle with code: jsfiddle

343
Add .next() everytime a function is called

Add .next() everytime a function is called

I basically want to know if its possible to add anothernext() every time the function is called, this is the function i have at the moment which sort of works but it always brings up the same post which isn't what I am looking for it to do

400