Uploading attachments and saving attachment data

The next step in the process is uploading and saving the file that's been selected by the administrator. In this scenario, we add the File and File Title inside the metabox by using the defined fields. Then, the administrator needs to hit the post's Publish or Update button to save the attachment along with the post.

Ideally, the attachment details should be uploaded and saved using AJAX in order to support multiple files without needing to update the post. In this scenario, we have used a normal form submit as we have not introduced AJAX yet and we need to understand the process of handling normal POST requests.

Let's take a look at the attachment saving process using the following code, which ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.