• Hello!

    I actually have 2 subdomains sharing the same database, but both with different database prefixes. Subdomain A has prefix abtf_ for its tables and subdomain B has prefix klmn_ for its tables. They both share the users, and the userdata, the keys, and cookies via the wp-config.php file. I made the needed changes in both configuration files and both wordpress installations work pretty fine. But my headeache comes when I try to make them share the plugin’s tables.

    I’m not using the multisite feature, and I would like not to use it for this.

    I want both installations of a plugin to use the same database tables, and I don`t know really how to do it, I’ve been researching for days, I tried to do something similar as I did in the wp-config.php for linking both sites, but didn’t work, I tried by building an alternative wp-config.php just for the plugin, and testing inside the plugin files to make it read the alternative wp-config.php, I tried to define custom constants inside wp-config…

    I’m totally lost. If someone could give me a hand, I would really appreciate it.

    Thank you in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @tiracles. What tables do you want the two WordPress installations to share? A particular plugin’s? What plugin?

    Some plugins allow you to define a custom prefix for their tables. If that’s the case for the plugin you’re using, you could define a prefix that is the same for both installations. For example, you could define the prefix as “wp_” for both installations, so that the tables would be named “wp_plugin_table1”, “wp_plugin_table2”, etc. This would allow both installations to use the same tables, as long as the prefix is the same.

    Another option would be to modify the plugin code so that it uses the correct table prefix for each installation. You would need to identify all the places in the plugin code where it accesses the database tables, and replace the prefix with the appropriate one for each installation. This would require some coding knowledge and could be time-consuming, but it would give you more control over how the plugin works.

    Thread Starter tiracles

    (@tiracles)

    The plugin is supportcandy.

    The tables cannot have the same prefix, as they are from 2 different wordpress installations, in the same database.

    I’m testing inside the plugin code but I cannot see where I could make any effective change on it, The plugin loads the wp enviroment.

    Moderator bcworkz

    (@bcworkz)

    If both sites use the same DB, you can use the global $wpdb connection object to directly query for any data in the DB. You’d create your own mySQL query to do so. The SQL would of course need to use the correct prefix and table name for the desired table, regardless of which site the table rightfully belongs. For example if site A has data in abtf_my_table, Site B can do something like $wpdb->get_results( "SELECT * FROM abtf_my_table WHERE foo = 'bar';" ), assuming the table has a foo field with ‘bar’ value.

    Thread Starter tiracles

    (@tiracles)

    Nice bcworkz, thank you! I’m gonna research that. I will keep you guys updated about it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sharing plugin tables between 2 sites’ is closed to new replies.