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
- How to use $wpdb to delete in a custom table
- Can i use php sql functions instead of $wpdb?
- Matching database content types to PHP types
- Does $wpdb->prepare not create a prepared statement that I can execute multiple times?
- wpdb::prepare was called incorrectly
- Custom query to get post names beginning with a digit
- Saving custom form data into database
- wp-content/db.php : where is this file?
- $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
- $wpdb prepared with search term
- WPDB->insert with special characters
- Is there a (better) way to access $wpdb results?
- $wpdb->prepare not working with update table prefix
- How to use prepare to query with variables
- Use $wpdb in wordpress theme files
- PHP syntax error when using wpdb update?
- 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
- $wpdb->replace / Replace or update primary key
- 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?
- Replicating the WP_Query ‘s’ param with $wpdb
- Need help writing a $wpdb query
- get the number of queries made on a page(inside my plugin)
- Doing a loop with multiple DBs simultaneoulsy
- $wpdb->insert query changes to SHOW COLUMNS query Output
- Fixing wpdb->get_results and wpdb->prepare?
- How does the WXR file differ from the WPDB?
- Modify the structure of data returned by $wpdb
- Get stock by custom meta field on all Woocommerce variable products
- Any possible way to make $wpdb->get_results() return anything else than array?
- Display fields as values in array from external SQL DB
- Getting id of poll from WP database
- I want to select the from values from database in WordPress? [closed]
- What is wrong with this wpdb update?
- Programmatically Creating Page using $wpdb and getting 404 error
- Constructing a dynamic WPDB query with multiple LIKEs
- Counting posts with argument without retrieving the posts
- $wpdb->insert inserting only f character in custom table
- Why does wpdb->update delete other meta?
- Increment integer field in database when WHERE needs to be dynamic [closed]
- Custom array from a query only write the last row of the query
- Getting variable from Database
- Querying Database with wpdb
- Create new database through static page code
- Custom $wpdb returns unexpected time based results
- Use $wpdb or other PHP script method to find/replace in WP database
- How to get specific attribute from DB
- WordPress “wpdb->update” – Append Text Value
- Need help converting get_user_meta [keys] into own array
- Can’t call WPDB inside RSS template
- $wpdb->get_results breaking page?
- Save sql file after doing insert wpdb
- Can I use wpdb to insert query results into a post?
- $wpdb->prepare error after WordPress update [duplicate]
- Query and get meta as object(stdClass) on wp postmeta table?
- How do I query a table?
- check that the data exists before sending it to wpdb
- WordPress get last inserted user id
- How to pass an input value into wpdb->Prepare
- WordPress SQL Prepare
- no result returns when using $wpdb->get_results with where clause
- SQL queries to another wordpress site
- PHP | left join avg query give me Array()
- update not working using wpdb
- get_posts() SQL Injection
- og:image functions.php
- What is the correct way to search 3 custom fields only in WordPress?
- How to work with constraints on wordpress user metadata?
- No result after wpdb->insert
- $wpdb select returns empty array
- Show error messages to a user when database insert fails
- Intermittent problem writing update_user_meta
- Rewrite SQL query as a prepared statement and use in foreach loop
- How to return count of items found in SQL query
- How to use WHERE NOT EXISTS query to avoid duplicate entry using $wpdb to save in custom table?
- Combine posts and postmeta
- wpdb insert working in one function, but not another
- wp_commentdata: error in documentation?
- Echo only gives me the first part of string
- esc_sql inserting weird chars to DB
- Retriving array size from serialized data
- How to update user profile or inputing any data to the wp db from external site?
- Can’t get expected result from a wpdb query
- Get comments after specific date
- Fetching wpdb data from a php file seems to break?
- selecting row using wpdb which contain special symbols
- Query Problem in Clustom Plugin
- Insert into db with foreach problem
- How does $wpdb->get_var work with offset?
- WordPress Query -> Ajax Query
- how to display tables via ajax
- WordPress / PHP: Check if column has value and then check if value in array