What is the easiest approach to iterate through the sub-sites (in Multi-Site network) and let's say add_option("xyz", 123) for each of site.


Well, you can get sites with get_sites and loop through them:

if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
    $sites = get_sites();
    foreach ( $sites as $site ) {
        // do something

I've found this so far to work for me:

foreach (get_sites() as $blog){
    // get_option (...)   
  • The only problem with this is that you use switch_to_blog which is very very bad for performance... And you don't need it to set option... – Krzysiek Dróżdż Feb 5 at 8:31
  • @KrzysiekDróżdż forget the "get_option". what are alternatives for itteration then without switch_to_blog ? So loop could be used. – T.Todua Feb 6 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.