Support » Networking WordPress » Switch_to_blog – is it really taxing on the frontend?

  • Hi,
    I run a medium sized MS network (~100 sites – 8mln pageviews a month).

    I need to broadcast some posts from one site to another, but I’ve read on the codex that switch_to_blog() should not be used on the frontend as it is very taxing.

    Just to be sure, I’ve made a little experiment on my local install, and created a simple shortcode that queries posts from another blog.

    [ms-posts blog=”blog-id” cat=”cat” tag=”tag”]

    which outputs a simple list of posts taken from the blog and taxonomies specified in the shortcode arguments.

    Now, from opening a post/page where the shortcode is included to opening a post/page where the shortcode is not included I see very little differencies in performance (just one more query called by WP_Query->get_posts).

    Am I doing something stupidly wrong and cannot see the dangers of switch_to_blog()?
    Or using it in this way (to query just one blog) is fine?

    thanks 🙂
    best

Viewing 3 replies - 1 through 3 (of 3 total)
  • > This switch is to be used for internal and admin area functions. It’s too expensive a query to run on the front end.

    I think the codex entry above is old. I know our web developers use it occasionally to pull content from other sites. There is overhead to the call(s) if you are going to run through a lot of sites; for example if you wanted to pull posts from all 100 sites.

    So my answer is: no switch_to_blog() is not that taxing.

    Thread Starter chickenrun

    (@chickenrun)

    Hi jkhongusc,
    thank you for your answer 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Switch_to_blog – is it really taxing on the frontend?’ is closed to new replies.