admin管理员组

文章数量:1290135

I understand that Transients API is used to cache data and should be intended to store data that is expected to expire.

However, please clarify the following.

Can set_transient() be used to store data in multi-site scenario? If yes, how is it different from using set_site_transient() function?

I understand that Transients API is used to cache data and should be intended to store data that is expected to expire.

However, please clarify the following.

Can set_transient() be used to store data in multi-site scenario? If yes, how is it different from using set_site_transient() function?

Share Improve this question edited Aug 29, 2016 at 12:53 James Vu 3,4193 gold badges24 silver badges45 bronze badges asked Aug 29, 2016 at 12:05 Maria Daniel DeepakMaria Daniel Deepak 16712 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

As the Codex suggests:

Essentially the same as set_transient() but works network wide when using WP Multisite.

One difference is that the transient name should be 40 characters or less in length. Also, while set_transient() sets transients that have an expiration time to not autoload, all transients added with set_site_transient will auto-load at all times.

In other words, the fundamental difference is in the auto-loading and since transients might be serialized, you could risk breaking things if referring to a blog (in MU) which has different settings/url/etc.

So the short answer is:

  • use set_transient for single blogs

  • use set_site_transient when you need something for ALL blogs.

Example of stored transients:

本文标签: multisiteCan settransient() be used in multisite