Clean database from unused tables

Backup your Database and then use DROP statements to delete the tables manually via tools such as MySQL Workbench, or MySQL Query Bench. There are many alternatives you can use that provide GUIs for backuping up, restoring, and modifying DBs. Here’s the WordPress DB schema, do not delete any of these tables: http://codex.wordpress.org/Database_Description Aside from … Read more

Is it possible to import a wordpress backup from a single site in to a multi-site configuration?

I imported/exported between a single wordpress blog and a multisite wordpress without problems, many times. Personally on a multi-site wordpress I have a parent generic theme and each website has it’s own child theme with as few files as possible, mostly only html/css for custom post types. Security issues or big complicated options are most … Read more

How to log database changes during an upgrade?

Why would you need to log them? They’re defined in the code itself. Look at wp-admin/includes/upgrade.php. Every version that changes the DB has a function defined that does the job. The changes made for version 3.4 are defined in the upgrade_340() function. The changes made for 3.3 are defined in the upgrade_330() function. And so … Read more

What is the easiest way to implement cascading database upgrade for my plugin?

Ok, to resolve these issues, let’s implement the cascading upgrade process which will handle both use cases. First of all lets implement our plugin activation hook, which will be our entry point: // define current plugin version define( ‘WPSE8170_PLUGIN_VERSION’, ‘2.0.0’ ); // define our database table name define( ‘WPSE8170_DB_TABLE’, $GLOBALS[‘wpdb’]->prefix . ‘wpse8170_test_table’ ); add_action( ‘init’, … Read more

how to show database content in wordpress post

For the sake of the example, I’ll assume you to have copied the relevant Table to the WordPress DB, to have named it wp_my_xtra_table and it to contain 3 columns (id,num_val,str_val). function wpse106832_shortcode_demo( $atts ) { global $wpdb; extract( shortcode_atts( array( ‘id’ => 1 ), $atts ) ); $table_row = $wpdb->get_row( ‘SELECT * ‘ . … Read more

Query WordPress database by registered date and role

I’m no SQL expert, but I think it would look something like this: SELECT * FROM mydatabase.wp_users INNER JOIN mydatabase.wp_usermeta ON (wp_users.ID = wp_usermeta.user_id) WHERE 1=1 AND wp_users.user_registered > ‘2014-03-15 00:00:00’ AND wp_users.user_registered < ‘2014-03-16 00:00:00’ AND ( (wp_usermeta.meta_key = ‘wp_capabilities’ AND CAST(wp_usermeta.meta_value AS CHAR) LIKE ‘%\”subscriber\”%’) ) ORDER BY user_registered ASC ;