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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315169a4622184.html
评论列表(0条)