How to add file upload to meta box in WordPress

For a project I’m working on, I had to create a file upload in a post meta. I wanted to utilize the WordPress media uploader so I cut down the manual labor, however all code snippets I found either did not work or broke the “Add media” button for the editor.

In order to accomplish the task at hand I’ll follow the following plan:
1. Register the meta box
2. En-queue the needed JavaScript
3. Write the JavaScript
4. Handle the meta box saving

 

1. Register the meta box

 

2. En-queue the needed JavaScript

 

3. Write the JavaScript

 

4. Handle the meta box saving

 

You can download the code for this how-to in

About Pavel Petrov 2 Articles |  15 How-tos

Pavel is a senior developer for the last 7 years, with extended interest in Linux administration, WordPress and Symfony.