database - Multisite setup creating custom table

If I'm running a multi-site setup and I create a new table and add it to the WordPress database, will it be accessi

If I'm running a multi-site setup and I create a new table and add it to the WordPress database, will it be accessible to all sites or is it created to be site specific?

If I'm running a multi-site setup and I create a new table and add it to the WordPress database, will it be accessible to all sites or is it created to be site specific?

Share Improve this question asked Jul 17, 2019 at 14:50 John SmithhhhhhhhhhJohn Smithhhhhhhhhh 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

It's up to you.

Normally when you create and query a table you use the $wpdb->prefix property as part of the table name. In a multisite install this prefix includes the current site ID. So if you use dbDelta() to create a table with the name $wpdb->prefix . 'tablename', then — assuming the default prefix of wp_ — this table will be created as wp_2_tablename, and wp_3_tablename etc. This ultimately means that each site in the network gets its own copy of the table, and you query the current site's table with $wpdb->prefix . 'tablename'.

However, if you want a single table shared across the network, then you should create and query it with $wpdb->base_prefix, which will be the same on all sites (wp_, if you use the default). That way if you query it with $wpdb->base_prefix . 'tablename' the same table will be queried regardless of which site you're currently on.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315169a4622184.html

相关推荐

  • database - Multisite setup creating custom table

    If I'm running a multi-site setup and I create a new table and add it to the WordPress database, will it be accessi

    10小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信