I'm on Wordpress 3.0.4 and I'm having a hard time deciding which way to go. The following is my problem:

I have a mysql database table widgets, with about 10 properties like id, size, color etc.

Now I'd like to integrate this table into Wordpress, preferably in such a way that I can get paginated lists of the widgets, show information on a single widget and have a flexible layout.

Preferably, I would like the ability to change a custom template in such a way that I can change the position of each property on the page (So maybe I'd like to put e.g. the size-property on top of the page on the left, later I might want to put it on the right bottom).

What would be the best way to store the widgets, retrieve them by using as much Wordpress build-in functions and how can I get this flexible layout as well?

I've written my own plugins before, so I have more than basic knowlegde on Wordpress/PHP/MySQL.


4 Answers 4


This is precisely what custom post types are for.

If it were my project, I'd scrap the custom table you have, set up a custom post type for your "widgets", add all your existing widgets as regular WP content, and use standard WordPress functions and templates to query and display them.

It's a bit of investment in the short term (if you have a lot of existing data you need to migrate), but in the long run it's best to have all your content in standard WordPress tables and display it using standard WordPress functions and templates--unless there's a really compelling reason not to.

  • Thanks MathSmath, in this case you mean that I convert the data in the table to posts? I guess in that case I would need to use post metadata in order to have the layout flexibility?
    – JanWillem
    Jan 6, 2011 at 19:34
  • Yes, you would use post metadata in order to add any number of custom fields (which correlate to your columns in your table) and then using that, create different layout based on which "widget" has which post metadata. Jan 6, 2011 at 20:11
  • 1
    For those who end up here via google... there are a grip of plugins out there that will allow you to import (and later update using) CSV files and convert them to custom post type content. Hurray for four years later.
    – Will
    Aug 6, 2015 at 23:08

If this table is in same database as your WordPress installation you can use $wpdb to get data from it. Otherwise you can instantiate your own wpdb object with connection details for other database.

I am not sure what do you mean by widgets in this case, doesn't sound like same thing as WordPress widgets? Since I am fuzzy on this I have no suggestions how to handle template for those.

  • Hi Rarst, with widget I mean a 'thing', could be a book, car, wine,basically anything with properties.
    – JanWillem
    Jan 6, 2011 at 19:34

FWIW, we've done something like this where we ARE pulling the data from an external data source. We created custom post types and created functions that are triggered by different wordpress hooks, with the result that we can show everything both up front to site visitors and in wp-admin. The posts are not stored in wpdb, not even as "proxy" posts.

So it IS possible to do it that way, although we have yet to figure out a way to use the trash can to delete them, and I ended up adding in my own wp-admin pagination links using JQuery.

Unless you have a very good reason to do it this way, I agree with @MathSmath: create a custom post type and store them as "real" wordpress posts.


As far as I know what you wanted to do can be easily achieved using Caspio. You don't even have to use any database. They provide a online database on top of which you can create all sorts of database-driven functioinalites. Here's a video I saw from them that shows how to build and embed a searchable contacts database on a WP site in just a few mins without any coding: https://www.youtube.com/watch?v=BgHV7ZPplo0

Hope this helps!

  • This is not an answer to the question. Feb 24, 2015 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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