How to integrate custom database table in WordPress and using WordPress functions

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 s
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.

Leave a Comment