Clean up very big and very dirty database
Yes, it is safe but always prefer a database backup before. You can also try the Minimise WordPress DB queries to clean more.
Yes, it is safe but always prefer a database backup before. You can also try the Minimise WordPress DB queries to clean more.
Usually you only have to use mysql.domain.com if connecting to a remote database. If that is what you are doing, then yes. It will be slower than a locally hosted database. Even if the domain resolves to the local server localhost should resolve quicker as it uses the loopback interface which bypasses network hardware.
posts_join is only a part of the full SQL query, the table you’re joining to is referenced earlier in the query. You can see the full query with the posts_request filter. See the documentation for the rest of the query filters.
“Blogs” or posts as they are called in WordPress are stored in the wp_posts table of your database. And custom fields related to your posts are stored in wp_postmeta table. So you should just be able to restore those two tables to get all your “Blogs”. This assumes your database is prefixed with wp_ of … Read more
Instead of adding new columns to the WordPress database, you might want to use the wp_usermeta table. It is used to store any kind of data about your users (just like the wp_postmeta for your posts and pages). To add fields on the registration form you can use the user_new_form action which is triggered by … Read more
In SQL Server Management Studio right-click your database and select Tasks / Generate Scripts. Follow the wizard and you’ll get a script that recreates the data structure in the correct order according to foreign keys. On the wizard step titled “Set Scripting Options” choose “Advanced” and modify the “Types of data to script” option to … Read more
You have probably figured it out by now, but just in case. I was also asked to pull data from an MS SQL server and present the data on a WordPress site. In my plugin, I stored the connection values (encrypted) as options. Here are the basics. Connection Function: public function rimsdb() { global $rimsdb; … Read more
It looks like I’ve managed to work it out. I needed to: JOIN to wp_posts With the link keys: TABLE : wp_postmeta column : meta_key TABLE : wp_posts column : ID SELECT * FROM wp_terms wpt LEFT JOIN wp_termmeta wptm ON wptm.term_id = wpt.term_id AND wptm.meta_key = ‘thumbnail_id’ LEFT JOIN wp_postmeta wppm ON wppm.post_id = … Read more
That’s not what esc_sql is for, or what it should be used for. Safely Escaping Variables In SQL Queries To make variables safe for an SQL query, use $wpdb->prepare, e.g. $table_name = “{$wpdb->prefix}myTable”; $myID = 12; $wpdb->query( $wpdb->prepare( “UPDATE `$table_name` SET `your_column_1` = 1 WHERE `$table_name`.`your_column_id` = %d”, $myID ) ); Notice that $myID is … Read more
You’re probably better off doing this with wordpress functions and adding a button which would delete all posts (or even having a shortcode that, when loaded, would do it). The reason I recommend doing this instead of SQL directly is that wp_delete_post() will take all the associated meta with it, which saves you having to … Read more