Switching database on the fly

Yes it works! This is the code, assuming both the databases share the same username & password: $wpdb->select(‘mydbname’); wp_cache_flush(); Once done, re-issue the same statements, with the original database name. Can’t see any performance issue at the moment, maybe because this is done when building a custom form picking data from two posts out of … Read more

Help With MySQL to WPDB Query Conversion

Instead of using $wpdb->query(), use $wpdb->get_results(). This method allows you to specify a return type so the query is returned as an associative array. For example … $results = $wpdb->get_results( “SELECT * FROM mb_download_manager WHERE filename=”” . $namemeta . “.zip””, ARRAY_A ); This will return you an indexed array of associative arrays … so you … Read more

Using GROUP CONCAT in my-sql query with wp_usermeta table

How about a Pivot Query? This would return rows that have first_name,last_name,user_login. You could then add whatever condition you wanted using a WHERE clause. SELECT MAX(CASE WHEN wp_usermeta.meta_key = ‘first_name’ then wp_usermeta.meta_value ELSE NULL END) as first_name, MAX(CASE WHEN wp_usermeta.meta_key = ‘last_name’ then wp_usermeta.meta_value ELSE NULL END) as last_name, wp_users.user_login FROM wp_users LEFT JOIN wp_usermeta … Read more

WordPress Settings Lost After Site Migration

Folks, I think I solved the problem! I switched the import file from UFT-8 to ANSI encoding, and the site appears to be working fine. I guess moving between Windows and Linux machines, encoding is really important. I’ve never had this problem before, but I will watch out for it in the future.

Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?

The only native import/export facility is the one under Tools in the admin. And even that needs an extension (plugin) for importing from different formats. It’s pretty straightforward to build one yourself. Something along the lines of: $options = get_my_options(); header( ‘Content-disposition: attachment; filename=my_export.txt’ ); header( ‘Content-Type: text/plain’ ); echo json_encode( $options ); exit; And … Read more