public function update() { $priority = $this->get_next_priority() - 1; if ($this->get_priority() > $priority) { $this->set_priority($priority); } if ($this->get_priority() < 1) { $this->set_priority(1); } $sql = "SELECT priority " . "FROM " . $this->table_name() . " " . "WHERE id = " . $this->get_id(); global $wpdb; $current_priority = $wpdb->get_var($sql); $new_priority = $this->get_priority(); if ($current_priority < $new_priority) { $sql = "UPDATE " . $this->table_name() . " " . "SET priority = priority - 1 " . "WHERE priority > {$current_priority} AND priority <= {$new_priority}"; $wpdb->query($sql); } if ($current_priority > $new_priority) { $sql = "UPDATE " . $this->table_name() . " " . "SET priority = priority + 1 " . "WHERE priority >= {$new_priority} AND priority < {$current_priority}"; $wpdb->query($sql); } parent::update(); }