WordPress choose wrong database

In case someone is interested. I made it work. I made a plugin and in the main php-file I wrote this. <?php function ir_load(){ include_once(ABSPATH . ‘load.php’); } function db_fix_login(){ global $wpdb; $wpdb->select(DB_NAME); } add_action(“wp_head”,”db_fix_login”, 0); ir_load(); db_fix_login(); ?> The ir_load() contains the database connection to my database. I made it a function in case … Read more

Export / import WordPress database

I normally use mysqldump and sed: on old server: mysqldump -u user -p OldWpdatabase > wpdb.sql sed -i ‘s/oldurl/newurl/g’ wpdb.sql on new server: mysql -u user -p NewWpdatabase < wpdb.sql sed is used to search and replace all the hard coded occurrences of the website if needed.

Maintain user profile data in a non-WordPress database

You can use the WPDB class to instantiate an external DB. Looks like roughly this: define(‘EXT_DB_USER’, ‘username’); define(‘EXT_DB_PASSWORD’, ‘password’); define(‘EXT_DB_NAME’, ‘ext_data’ ); define(‘EXT_DB_HOST’, ‘123.123.123.123:3307′); $wpdb_ext = new wpdb(EXT_DB_USER, EXT_DB_PASSWORD, EXT_DB_NAME, EXT_DB_HOST); then you just call $wpdb_ext with normal WP functions just like you would #wpdb. For log in info it’s usually easiest to sync login … Read more

Handling large N data in WordPress

Custom table(s). WordPress posts are not structurally a fit for what you are doing. Trying to use them for this will result in a lot of unnecessary data processing and storage. But you need to think through your own database design and you need to be good with SQL or you will end up inefficient … Read more

Saving into post_excerpt or post_content

There is no difference in storing data into the post_excerpt field versus the post_content field. If you look at the source code (line 2700) you will notice both post_excerpt and post_content won’t be filtered.

Merging two wp_posts tables while avoiding duplicates

Import the new table as wp_posts_2, then join them and delete all duplicates based on post_content; then merge the two tables. The following SQL query (untested!) should give the posts from the new table to be deleted: SELECT wp2.* FROM wp_posts_2 as wp2 LEFT JOIN wp_posts as wp ON wp2.post_content = wp.post_content WHERE wp2.post_content = … Read more

Use mulitple usernames?

WordPress does not allow this “configuration”. And I seriously doubt you would have any luck writing a plugin that would take care of this in a complete way. The WPDB class is heavily utilized throughout the site, and sifting through read-only vs write-enabled uses would be daunting.

Connect another DB and fetch records from some tables

here is what I did with slight change as per your need. May be it will helpful for you. 🙂 function fetch_news() { global $wpdb; $wpdb_backup = $wpdb; // backup existing instance $wpdb = new wpdb( NEWS_DB_USER, NEWS_DB_PASSWORD, NEWS_DB_NAME, NEWS_DB_HOST ); // create new db instance wp_set_wpdb_vars(); // add variable $news_sql = $wpdb->get_results(“SELECT * FROM … Read more

Migrating from Existing MySQL Setup to WordPress

If you’re fairly well-versed in WordPress plugin development, you could write a couple plugins, one to create your users with wp_create_user(), and another to insert your articles as Posts using wp_insert_post() (which, among other things, allows you to specify the post_author on each post that you insert). If you’re not so comfortable writing plugins, then … Read more