Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

We currently have a plugin that creates a new WP table, but it recreates the wheel when it comes to managing/updating data. It would be a good candidate for custom post types, but we don't want to pollute the wp_posts table.

Use case: We're creating a specific job board for a company that lists 100s of jobs, and we want to keep the tables clean for other php scripts outside of WP that will also be accessing the same data. Input and management would be handled by the standard WordPress APIs.

Question: I want to use WP's custom post type functionality, but use a different db table. Thoughts? Directions? Is it possible to simply tell WordPress to switch tables for a certain query?

Related: Difficult to read and understand, and not entirely the same: Use Custom Database with Custom Post Type

share|improve this question

1 Answer 1

I don't think you can do this. Maybe you could use a whole new database, but it seems unlikely you could add a new table for managing a custom post type. For one thing, a custom post type is stored in the wp_posts table, but some of the data for it gets stored in the wp_postmeta table (especially any post meta fields). And if you have a taxonomy with it, that uses 3 different tables. And if your plugin needs to store any options those would be in another table.

I wouldn't worry about polluting the wp tables, it is how they are made to work. Part of its power is the extendability that is built in and easy to use.

You could maybe provide a way to remove your post type and all of its posts if you wanted to be able to completely remove it.

share|improve this answer
1  
That last part makes sense about making sure to clean up stuff, but that should be a standard operating procedure for all WP plugins. Thanks –  Dan Gayle Aug 23 '12 at 21:30
    
Yeah. I don't disagree with that. You just have to be careful. Users don't tend to expect a plugin to lose its settings when they deactivate it. In fact it would almost always be detrimental at some point when a user needs to test something and deactivates the plugin only to find they lost everything. So you want to make sure it is a button or link on the settings page that makes it very clear that this will reset everything and is undoable. I may not be telling you anything new... –  Jake Aug 24 '12 at 5:45
    
Plugins should delete their data only on uninstalling, so you need to use register_uninstall_hook or use uninstall.php. I think with custom post types case is bit different, data is big and more important, so deleting them should optional as @Jake mentioned. –  Mamaduka Aug 24 '12 at 8:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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