WordPress Database Charset/Collate

There are $wpdb->charset and $wpdb->collate. I am not sure if or when one of these values might be empty, so it is better to prepare for empty values … From my DB class: /** * Get table charset and collation. * * @since 2012.10.22 * @return string */ protected static function get_wp_charset_collate() { global $wpdb; … Read more

delete_option() and update_option() returning false

The delete_option() function will return false if the option does not exist. The update_option() function will return false if the option already has the same value as what you’re trying to update it to. Both will also return false if the SQL query itself fails for whatever reason.

Changing the Database Connection Error Message

Basically, if you create a PHP file named db-error.php and put under /wp-content/, you’ll get what db-error.php will have. Here is my template on CodePen. This is example : <?php header(‘HTTP/1.1 503 Service Temporarily Unavailable’); header(‘Status: 503 Service Temporarily Unavailable’); header(‘Retry-After: 3600’); // 1 hour = 3600 seconds mail(“[email protected]”, “Database Error”, “There is a problem … Read more

Migrating data between local and development server

Assuming your wp-config.php is already in place and in order: Step 1. Mysqldump your development database Step 2. Replace all instances of development.domain.com to production.domain.com^^ Step 3. Login to MySQL, run a SOURCE command to import data e.g. source /path/to/file ^^ How to replace all instances of old domain with new: (1) Copy the script … Read more

Get posts by menu ID

I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the wp_get_nav_menu_items() function that helped me. I finnally came with this, 220 was my menu_id $navcat = wp_get_nav_menu_items(‘220’); foreach ($navcat as $obj) … Read more

what is the wp_5_posts table in the database?

Those are from a multisite install. The numbers represent the blog_id and the tables are created when you add a new site to your network. http://codex.wordpress.org/Database_Description#Multisite_Table_Details http://codex.wordpress.org/Create_A_Network#Step_4:_Installing_a_Network

Display data from a non wordpress database on a page template

As Ben suggested, you need to pass the connection details when creating the wpdb class: $newdb = new wpdb( ‘user’, ‘password’, ‘database’, ‘hostname’ ); You should also test that the query actually returned something before using the result in a foreach loop: if ($rows) { foreach ($rows as $obj) { … } }