public function set_attachments($attachments) { $this->clear_attachments(); $menu_order = 0; foreach ($attachments as $attachment) { $attachment->post_parent = $this->id; $attachment->menu_order = $menu_order; $attachment->save(); $menu_order++; } }