我想要一个HTML列表,用户可以通过拖放操作重新排序(我已经这样做了)
然后我想获取当前订单并在按钮单击时用php发布
JS
jQuery(document).ready(function(){
jQuery("#new_fields").sortable({
cursor:'move',
// post
update:function(){
var order=jQuery('#new_fields').sortable('serialize');
jQuery.ajax({
type: "POST",
url: "<?php bloginfo( 'myurl' ); ?>/wp-admin/admin-ajax.php",
data: "action=update_field_order&" + order
});
}});
jQuery("#new_fields").disableSelection();
var ul = document.querySelector('ul');
for (var i = ul.children.length; i >= 0; i--) {
ul.appendChild(ul.children[Math.random() * i | 0]);
}
});
php
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/page/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->
<?php
function updateFilmOrder(){
global $wpdb;
foreach ($_POST['field_id'] as $position => $item)
$wpdb->query("UPDATE table_name SET list_order='{$position}' where id=$item");
die();
}
add_action('wp_ajax_update_field_order', 'update_field_order' );
?>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
和HTML(ul)
<h2>Place the .....</h2>
<ul id="new_fields">
<li id="field_id_1" class="ui-state-default">The Abyss</li>
<li id="field_id_2" class="ui-state-default">Aliens</li>
<li id="field_id_3" class="ui-state-default">The Terminator</li>
<li id="field_id_4" class="ui-state-default">Terminator 2: Judgement Day</li>
<li id="field_id_5" class="ui-state-default">Avatar</li>
<li id="field_id_6" class="ui-state-default">Titanic</li>
<li id="field_id_7" class="ui-state-default">Piranha II: The Spawning</li>
</ul>
我需要知道如何获取订单以及如何发布