wordpress - switch_to_blog errors when connecting to another wpdb -


i have created function within wordpress theme allows site connect second multisite installation (the "hub") , grab our staff directory, emergency alert information, , headline news. second multisite broken down several blogs:

emergency notifications: site 2 campus directory: site 3 events calendar: site 4 news: site 5 dining calendar: site 6

you can see them in action @ http://inside.scrippscollege.edu

the problem comes when site , our new external site share blog_id. example, site 3 (our faculty page) on inside scripps , site 3 (emergency response) on external staging site cannot run directory function because use same blog_id. don't know how work around problem, or troubleshoot it.

the function begins this:

global $wpdb; $wpdb_backup = $wpdb; // copies global wordpress variables later $wpdb = new wpdb('xxxx', 'xxxx', 'xxxx', 'xxxx'); $wpdb->set_prefix('wp_'); $wpdb->show_errors();  global $blog_id; global $switched;  switch_to_blog(3);  // switches on the directory portion of hub 

after running query, end function so:

restore_current_blog();  // restores switch_to_blog() function $wpdb = $wpdb_backup;  // restores global wordpress variables return $output; 

if define dieondberror @ top, i'll error this:

wordpress database error: [you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'where option_name = 'category_children' limit 1 /* [site' @ line 1] select option_value option_name = 'category_children' limit 1 /* [site/emergency/] in [/functions/office.php:65] */

line 65 start argument:

$news_posts = new wp_query( $args ); // select posts we're going use 

so, there step i'm missing switch blog keep blog_id integrity of search maintained? have nagging suspicion glitch contributing similar errors sites matching blog_ids stop working until clear our host's cache.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -