0

I have basic jQuery UI sortable code that works perfectly. I just want the position of each item to save when a user changes it.

I am using Wordpress multisite version 3.8.1 and each site will have it's own sortable area so it needs to save in a different database for each site.

I did see this post but it isn't quite what I was looking for. It might help though.

HTML:

    `<ul id="sortable">
     <li class="ui-state-default">Item 1</li>
     <li class="ui-state-default">Item 2</li>
     <li class="ui-state-default">Item 3</li>
     </ul>`

jQuery:

    `<script>
     $(function() {
     $( "#sortable" ).sortable();
     });
     </script>`
1

if you use the stop function when you intialise .sortable() you can ajax send the new order to a script, which (when you write it!) would save the new order to the database.

jQuery(function(){

jQuery("#sortable").sortable({

    stop: function (event, ui) {

        var new_order = jQuery(this).sortable('serialize');
        jQuery.post( "http://www.thissite.com/wp-admin/ajax.php", { action: my_custom_ajax_save, order: new_order }, function( data ) {

            console.log('ajax sent and response received');     

        });
    }
});

})

If you give more context we could help with the actual save. For example, if its a post you could save to the postmeta database nicely, what exactly are you saving?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.