“WPMU Functions/switch to blog”的版本间的差异

跳转至: 导航搜索
Related Resources

2016年5月6日 (五) 06:12的最新版本

Note: If you're using WordPress Multisite, you can instead use switch_to_blog()


Switches the active blog until the user calls the restore_current_blog() function. This function is useful if you need to pull posts, or other information, from other blogs, you can then switch back after using restore_current_blog(). Using this function will not load plugins that only run on the blog you switch to.

This switch is to be used for internal and admin area functions. It's too expensive a query to run on the front end.


(integer) (required) The id of the blog you want to switch to.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9


This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

The name of the parameter.
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
A short description of the parameter.
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

Return Values

True on success, false if new_blog was blank, or if you tried to switch to the blog you're on.
Sets up a global variable called: switched.


%%%<?php switch_to_blog($new_blog) ?>%%%



      for global variables, since it is being changed or updated from time to time,
      please refer to Related Resources for more information
   global $switched;
   echo 'You switched from blog ' . $switched . ' to 7';
   echo 'You switched back.';


Source File

switch_to_blog() is located in onlyincludecode/wp-includes/ms-blogs.php/code/onlyinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.


  1. filename
  2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.


Link to the stable version: pre检查到模板循环:模板:Trac/pre

Link to trunk: pre检查到模板循环:模板:Trac/pre



Related Functions

To easily revert back to the blog you were on, restore_current_blog()

Related Resources

Please refer the following links for related variables.WPMU_Global_Variables