Support » Plugins » Hacks » plugin development with custom database tables

  • Hola,

    Bit more of a generic development question, so apologies if this is the wrong section, but I am rather lost after looking at the documentation and googling with this.

    So wanted to ask seasoned developers if there is a better solution to do what I want. Writing a plugin at the moment that will create 2 extra tables to core wp which will store some data that registered users can post.

    Say as an example its a book database, so one table will have book category and the other book titles (with some random meta data, like dates, users who post that). So the tables would look like:

    id, varchar, date, user
    id, int, date, table_1_link, user

    Something along these lines, so the real question is, can I use the API that wp provides to create this (and if so a tip pointed at the right direction would be appreciated)? For example to output an actions menu for a specific “page” looking url or I don’t quiet mind how actions are represented as urls, just as long as they are sensible. Can I somehow catch the actions that I want using wp rather then referring to $_POST[‘action’] in the plugin?

    Tried using custom_post_type, but I don’t think this is what I am looking for, since the data I want to store/display isn’t a massive text field but is not shared between users (so their book database example would be private to themselves).

    So far the only way to do what I want involves creating a page where the plugin runs from with [plugin] and in the plugin trying to catch actions for new/edit/delete using $_POST. Is there a more sensible framework like solution for this in wp (that I just keep missing)?

    Cheers for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi.
    If i get it, you want:
    – sort of a private book ‘shelve’ per user?
    – the books are not posts

    again, if I get it right and it’s all is around a user, I’d think of using the user profile actions. I’d add an option page to the user admin area or just customize the native profile, adding whatever i need there: field groups, download buttons, ect.. it’ll insert the book data into a user db metadata so i’d have full control over the output based on a user id and i won’t need a plugin.


    Creating the extra tables with the plugin initialisation works fine, that’s not the problem :).

    Well the book thing was just an example, realistically I am expecting up to 10 entries in the first table and maybe several hundred+ (if I am lucky) in the second one per user. Would this be efficient in wp environment to use metadata over a separate table with soft links (storing userid as the owner of the entry)?

    From what I found so far my option is to write the data handling myself ie in the plugin to call $_POST[], check if they are submitted ect. I was mostly wondering if there were provisions to catch “basic” actions of posting some data from a form embedded in a page (be that a real page or just a url route, which ever makes more sense to implement).

    I think displaying data isn’t that much of a problem from me, its more grabbing/parsing it when users post the form from a url. I want to write the plugin in such a way that it would not be limited to a hardcoded url for example so that it would catch that form from any installation/whatever you want to use as http://www./books/ or http://www./buckets and catch actions in the wp way rather then however I would end up using $_POST[] directly.

    I am pretty new to this, and have not found guidelines to parsing user input dynamically yet. If this is even possible… But I do like the ease of using wp for the CMS side of things.

    Moderator bcworkz


    I’m not keen on actions in the permalink structure, it should be reserved for data structure terms IMO. You can still add URL parameters to permalinks though there’s no file spec: . Of course, if there’s much data involved, you don’t want to use URL parameters. For POSTing forms, I would embed the action in a hidden input field. I see no issue with grabbing action values directly from $_GET or $_POST… straight from the source! Much easier than trying to parse the URL as well.

    Though you have your own tables, you can still use the methods of the $wpdb global object to interact with the database.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘plugin development with custom database tables’ is closed to new replies.