admin管理员组文章数量:1419640
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 badges1 Answer
Reset to default 3It'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.
本文标签: databaseMultisite setup creating custom table
版权声明:本文标题:database - Multisite setup creating custom table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745315169a2653119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论