Doing my first plugin with 3.1 Everything is great, but I need to store the data now. My data is sufficiently complex that it requires custom tables (as opposed to options). So now I am wondering how I save the data. Normally, I would just create a processing page to handle it, but that doesn't seem like the best way within the WP API. How do I go about saving my form data from my plugin settings page into my custom tables? Thanks!

EDIT: To clarify, I know how to code it, I am not sure architecturally the best way to do it.

  • If you can explain your use-case you are likely to get a better answer. Commented Apr 10, 2011 at 16:39
  • Thanks. Hmm, ok. I've got an admin page for my plugin. In the admin page, you setup a simple survey. (survey and question tables) I've got my form setup properly, I want to know where to set my form action. Do I send it to another page and redirect back to the whichever other admin page? Do I send the form back to the same page? Do I use AJAX? Or maybe it doesn't matter how I do it? Just trying to see if there is a best practice, otherwise I'll just go with a separate page and redirect back to the admin page (just seems kinda hackish)
    – Wil
    Commented Apr 11, 2011 at 8:02
  • 1
    For future reference it's best to explain your use-case in the question, not in the comments. Many people don't go to the extra effort to also read the comments. It also helps to include source code in your question that shows what you are currently doing. It's easier for us to fix your source code than to write it from scratch. Commented Apr 15, 2011 at 11:29

1 Answer 1


Not that there is specialized API for something exactly like that.

  1. Create your table, see Creating Tables with Plugins in Codex.

  2. Process submitted form (since you are not using higher APIs, don't forget to check for capabilities, use nonces and such).

  3. Write data to your custom table, using $wpdb.

  • 1
    I know all this, and I undestand it, but I am asking architecturally what is best. A seperate page to take the request and redirect? AJAX? Use the same page? Trying to understand best practice.
    – Wil
    Commented Apr 10, 2011 at 14:25
  • @Wil best practice is Settings API :) If you need something else - then it's up to you how to put it together. Personally I'd probably try to use Settings API anyway, just writing data to database in sanitizing function instead of saving it as option.
    – Rarst
    Commented Apr 10, 2011 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.