Use switch_to_blog( $new_blog_id )
instead.
You can find the function in wp-includes/ms-blogs.php
.
Update
$wpdb->set_blog_id()
doesn’t change the global variable $blog_id
which is returned by get_current_blog_id()
. switch_to_blog()
does change the global variable.
Related Posts:
- How to fetch an array in $wpdb?
- Undefined offset: 0
- $wpdb->get_results in not an array
- $wpdb->get_row() only returns a single row?
- How to return number of found rows from SELECT query
- wpdb->insert: do I need to prepare against SQL injection?
- How to parse row results from $wpdb -> get_results
- Why $wpdb->show_errors() and print_error() is showing an output even if the query output is correct?
- what is the way to see the currently executing query in wordpress?
- Fetch array with $wpdb
- How do I check for a duplicate record before inserting using wpdb
- WordPress 4.8.1 uses mysql_connect which doesn’t work with PHP 7
- How to use $wpdb to delete in a custom table
- $wpdb->insert not working in any way
- WPDB prepare – like % – placeholders?
- Can i use php sql functions instead of $wpdb?
- $wpdb->update multiple rows, like IN in normal SQL
- Matching database content types to PHP types
- $wpdb->get_results(…) returns empty array despite correct query
- Does $wpdb->prepare not create a prepared statement that I can execute multiple times?
- get_results on large datasets
- $wpdb->insert() and Values for Datetime Columns?
- $wpdb->last_error doesn’t show the query on error
- $wpdb->delete column values IN ARRAY()?
- wpdb::prepare was called incorrectly
- Avoiding “Usage of a direct database call is discouraged”
- Display data from a non wordpress database on a page template
- dbDelta does not create Table, but returns success
- Theoretical Multi-Server WordPress Setup with Shared Users
- Custom query to get post names beginning with a digit
- Change post status based on meta value
- wpdb->insert not working
- queries inside of a class
- Saving custom form data into database
- passing variables as parameters to stored procedures via wpdb from php-script
- Get data from database table by post_id to get data from second database table
- Stackoverflow type of badge plugin giving warnings in WordPress 3.5
- wp-content/db.php : where is this file?
- Quotes in table name
- Delete/replace img tags in post content for auto published posts [closed]
- $wpdb sql help. Select post id and post meta value based on 2 other post_meta values
- $wpdb->get_results() returns good result only in first foreach iteration
- $wpdb->insert – inserting multiple rows
- How to display only first value of database column in WordPress
- Speed optimization of $wpdb->get_results
- Print out WordPress user ID – two sites with same code but different output
- How do I create a single.php for a specific category?
- $wpdb prepared with search term
- WPDB->insert with special characters
- What does wp_update_post() do that the $wpdb class does not?
- How Can I Use $wpdb in PayPal IPN file?
- $wpdb is get_results escaped
- $wpdb->query() multiple query support
- wpdb-> not adding prefix to custom table
- Is there a (better) way to access $wpdb results?
- Using $wpdb generates DB error
- WordPress insert NOW() in TIMESTAMP column returns all zeros
- Inserting data into `post meta` table?
- How do you use prepare when asking for a list of id’s
- Set media metadata (i.e. “dimensions” field) on SVG file after extracting it with a filter
- $wpdb prepare issue with mysql DATE_FORMAT
- How-To: wpdb Insert Record With Date
- WPDB: how to get the value of a field in a custom database table
- $wpdb->prepare not working with update table prefix
- How to use prepare to query with variables
- Use $wpdb in wordpress theme files
- Can’t use get_results() in ajax query
- How to pass NULL in where array for $wpdb->update
- how to execute different sql query in non-sanitized $wpdb->get_results function
- $wpdb not returning data
- PHP syntax error when using wpdb update?
- Get random row from custom table
- How to get top 10 user is based on user meta value
- $wpdb Query Result not coming but in phpmyadmin it works [closed]
- WPDB update row with != in where clause
- store custom WP table names in a global variable
- wpdb prepare: passing varible number of fields as second argument
- $wpdb insert array
- I am not understandinhg $wpdb->prepare correctly
- Wpdb query for comment meta for current post
- How to update records using $wpdb?
- wpdb->get_row() / get_results – is it possible to return an object instances of my own class?
- Problem in creating table through plugin code
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- I want to update my postcontent with $wpdb
- How to iterate through database until it find a match
- How to save html and text in the database?
- Export WordPress Table to CSV from page
- XOR functionality for meta_query
- How to email user after inserting the username in database in WordPress
- $wpdb->replace / Replace or update primary key
- Join inside a wpdb query.. confused!
- WordPress get pagination on wpdb get_results
- Create an array with a string key from wpdb->get_results
- $wpdb – do you have to use foreach even if there will always only be one result?
- How to Modify this $wpdb query to accept an array of post statuses
- Replicating the WP_Query ‘s’ param with $wpdb
- Why doesn’t my insert query work?
- Need help writing a $wpdb query
- How to prevent $wpdb->prepare stripping a leading zero in variable value?