Here’s what we are doing, in terms of what MySQL knows:
The form pages are in the “wp_posts” table, and custom fields are stored in the “wp_postmeta” table in WordPress. The “wp_postmeta” table tracks the “post_id” that each custom field is connected to. The end result of our query should display the column called “post_title” from the “wp_posts” table, and it should display the value inside “meta_value” from the “wp_postmeta” table if the “meta_key” value is called “FileName”.
I know this sounds extremely confusing; that’s because it is.
So let’s get to the code. This shows me the output of all of my uploaded forms that have a value for the custom field “FileName”:
SELECT wp_posts.post_title, wp_postmeta.meta_value FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID=wp_postmeta.post_id WHERE wp_postmeta.meta_key = 'FileName' ORDER BY wp_postmeta.meta_value
When I typed this in the MySQL Editor, I got a nice long list that showed Form Titles, then Form Filenames sorted by Filename (I sort by filename because all of our forms are prefaced with a four digit number).
Now that you have the list of forms and their filenames, we want to insert this into the WP-DownloadManager’s database. The first time I did this, I copied it all to an excel file, reformatted the data, saved as a CSV, uploaded to my server, and so on. But MySQL can handle all of that for you very easily.
But I should point out that WP-DownloadManager tracks things that WordPress doesn’t. Specifically, you won’t have the file size until you go into the manager and click “Edit”. Then PHP automatically calculates the filesize. (I don’t think there is a way to have MySQL calculate this as part of our import, but I could be wrong – let me know). (UPDATE: You can run another script to populate all the file sizes – see the end of this article). Permissions and Categories are not available either, but it wouldn’t be impossible to map your post categories over to the WP-DownloadManager categories. I just didn’t need this so I skipped it.
Executing the following code will take your results and map them to values inside the WP-DownloadManager’s database: