ajaxsortprod.php
<?php
include_once("../../../wp-config.php");
$movedPr = $_POST['cat_id'];
$rowCount = 1;
foreach($_POST['pid'] as $pos => $item)
{
//$qu = "UPDATE `products` SET `prod_order` = '$rowCount' WHERE `prod_id` = '$item'";
//was just updating products. Changed to the assoc tables
$qu = "UPDATE `category_assoc` SET `p_order` = '$rowCount' WHERE `prod_id` = '$item' AND `cat_id` = '$movedPr'";
$wpdb->query($qu);
$rowCount++;
}
?>
adminfunctiions.js
ajaxpath2 = "../wp-content/plugins/products2/ajaxsortprod.php";
jQuery(document).ready(function(){
jQuery('.sort').sortable({
cursor: 'move',
axis: 'y',
update: function(e, ui) {
href = ajaxpath2;
jQuery(this).sortable("refresh");
sorted = jQuery(this).sortable("serialize", 'id');
jQuery.ajax({
type: 'POST',
url: href,
data: sorted + "&cat_id=" + cat_id,//send the data in a string
//the cat_id is declared on products.class.php
success: function(msg) {
//do something with the sorted data
alert("Your products have been re-ordered");
}
});
}
});
});