wpdb::set_blog_id() WordPress Method

This method allows you to change the blog id. This is useful if you need to connect to a different blog than the one you are currently connected to.

wpdb::set_blog_id( int $blog_id, int $network_id ) #

Sets blog ID.


Parameters

$blog_id

(int)(Required)

$network_id

(int)(Optional)


Top ↑

Return

(int) Previous blog ID.


Top ↑

Source

File: wp-includes/wp-db.php

	public function set_blog_id( $blog_id, $network_id = 0 ) {
		if ( ! empty( $network_id ) ) {
			$this->siteid = $network_id;
		}

		$old_blog_id  = $this->blogid;
		$this->blogid = $blog_id;

		$this->prefix = $this->get_blog_prefix();

		foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
			$this->$table = $prefixed_table;
		}

		foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
			$this->$table = $prefixed_table;
		}

		return $old_blog_id;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.