[wp-hackers] Why do some user meta entries use the table prefix in the meta key?

John Blackbourn johnbillion+wp at gmail.com
Mon May 13 10:15:27 UTC 2013


On 13 May 2013 10:21, David Anderson <david at wordshell.net> wrote:
>
> On 13/05/13 10:04, David Anderson wrote:
>> I don't get this.... as long as all the sites within the network are
>> still using the same database and table prefix, then the meta key
>> prefix is still an invariant, isn't it? i.e. It only provides
>> something useful if the different sites within the network are
>> actually using a different table prefix. Otherwise, the same effect
>> could be achieved by just using a fixed string instead of the
>> $table_prefix setting. Or am I missing something?
>
>
> I could have been clearer here. I understand the need for the blog ID 1_, 2_
> to vary. It's the reason for including the apparently invariant wp_ that I'm
> not clear on.

The database prefix with the blog ID appended acts as a UUID within
the given database. This allows you to share your users and usermeta
tables between WordPress installs in the same database, because each
has a different database prefix.

Example: I have two Multisite installs which share a users and
usermeta table. The resulting usermeta keys would be, for example,
"foo_{n}_" for one site and "bar_{n}_" for the other. If the database
prefix wasn't prepended there would be key collisions.

John


More information about the wp-hackers mailing list