Using WPDB to output raw XML fails because of wp-blog-header.php

Include wp-load.php, not wp-blog-header.php. Better yet, hook onto the execution of a standard WordPress request and die early. isset( $_GET[‘my_conditional_check’] ) && add_action( ‘plugins_loaded’, ‘my_xml_output’ ); function my_xml_output() { // do my stuff exit; } This’ll run WordPress, then my_xml_output(), then die before the request is actually parsed & the template is loaded/rendered: http://example.com/?my_conditional_check

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.