1

I decided to ask this question as searching online left me really overwhelmed and not knowing which direction to take.

I am about to tackle a project that has its own custom database (finished e-r design) in MySQL, and I want to use Wordpress as its CMS.

  1. Can I make custom post types but pull/save records from/to the custom database? if so, any link to resources would be much appreciated, like:

    • Should I merge the databases or can I keep working them independently?
    • For the custom post type's admin area, how do I use this to pull/save entries from/to the custom database's table(s) for individual records?
    • Do I use/make custom fields in the custom post types and then rely on some hook to pull/save them from/to the custom database?
    • Will I be able to delete the posts in Wordpress and also delete the corresponding entry in the custom database?
  2. Is there a wiser way to go about this whole thing? I'm very open to suggestions/informed guidance.

I found the following resources, but I just can't pull them all together:

  1. https://stackoverflow.com/questions/7538337/save-the-data-of-custom-metabox-to-database - but how do I do this for a custom database?
  2. http://www.deluxeblogtips.com/meta-box - is this something I should look at or is it overkill?
  3. http://Wordpress.org/support/topic/migrate-from-custom-database-to-Wordpress-database - this kind of hits the spot but not quite; if I want to work on the custom database without merging it with Wordpress what do I do?

Again, I'm just fumbling my way around these options as these are what I've come across so far. If someone knows a better/more correct way to tackle the whole problem and not just piecing-together disparate info ending up with a frankensteined setup then I would love to hear what you have in mind.

1
  • 1
    Please don't write you'd do privately in chat. Well written english is highly appreciated.
    – kaiser
    Commented Apr 2, 2012 at 5:37

1 Answer 1

2

What I understand is you want to update records/table to another database from wordpress.... well you can achieve this in wordpress 3.1> using

$newwpdb = new wpdb("mysqluser","mysqlpassword","mysqldbname","mysqlhost");

Then using $newwpdb you can access table from new database and perform all operation on it like edit/delete update/insert... same as $wpdb do wordpress....

Hope that helps or you may post your code for more understanding....

4
  • definitely promising, @Rajeev.. can i use this too for custom post types? especially for having admin boxes when editing the post and all? for example, when i'm on the add/edit post for the custom post type, how do i assign the value of a meta box to an entry in the custom database? and when pulling the post, the entries in the custom database will go with it as well?
    – Ana Ban
    Commented Apr 2, 2012 at 7:25
  • to clarify: i need to use the custom db for custom post types, especially for having admin boxes when editing the custom post.. so when i'm on the add/edit post for the custom post type, how do i assign the value of a meta box to an entry in the custom database? and when pulling the custom post for display/edit, the entries in the custom database will go with the custom post as well? and then for deleting the custom post, the entries in the custom database will be deleted as well? thanks much
    – Ana Ban
    Commented Apr 2, 2012 at 7:35
  • @AnaBan You can use 'save_post' and such hook in wordpress and then within that hooks you can call for your new db and do relative operations(in fact in both database tables you first need to store and/or have relations to each other)... Commented Apr 2, 2012 at 9:39
  • hmm.. alright, i'll work on this and see how it goes. thanks, @Rajeev
    – Ana Ban
    Commented Apr 2, 2012 at 11:28

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.