Search code examples
phpdatabasewordpresspluginsmultisite

Local change of database inside wordpress plugin


I have wordpress multisite and booking plugin on each. I would like them to share tables in database (so "all these" plugins will use single, chosen by me, WP DB).

This plugin utilizes get_post(), get_post_meta() etc. It doesn't query DB directly. My idea was to create something like local config or maybe local $wpdb global redefinition? I don't know how to do this though.

Or maybe is there a better way?


Solution

  • It looks like the best way will be to have one site actually host the database, and then in the plugin on the other sites, when it comes time to make the db call you will use switch_to_blog , make your db calls, and then restore_current_blog.

    https://codex.wordpress.org/WPMU_Functions/switch_to_blog https://codex.wordpress.org/WPMU_Functions/restore_current_blog

    make sense?