add_action( \'admin_footer\', \'my_action_javascript\' ); // Write our JS below here
function my_action_javascript()
global $wpdb;
$pageposts = $wpdb->get_var("SELECT max(menu_order) FROM $wpdb->posts WHERE post_status = \'publish\' AND post_type =\'post_trainers\'");
?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
\'action\': \'my_action\',
\'whatever\': <?=$pageposts?>
};
$.post(ajaxurl, data, function(response) {
if($(\'#menu_order\').val()==\'\' || $(\'#menu_order\').val()==\'0\')
$(\'#menu_order\').val(response);
});
});
</script> <?php
}
add_action( \'wp_ajax_my_action\', \'my_action_callback\' );
function my_action_callback() {
global $wpdb; // this is how you get access to the database
$whatever = intval( $_POST[\'whatever\'] );
$whatever += 1;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
我昨天正在解决这个问题