(function($) { 'use strict'; wp.customize.bind('ready', function() { $('.sortable-posts-list').sortable({ update: function(event, ui) { var $list = $(this); var postIds = []; $list.find('li').each(function() { postIds.push($(this).data('post-id')); }); var $input = $list.closest('.customize-control').find('input[type="hidden"]'); $input.val(postIds.join(',')).trigger('change'); } }); }); })(jQuery);