Using source control with WordPress

Have a look at this older question: How to: Easily Move a WordPress Install from Development to Production?. It covers migration and deployment of WP installations. For your more immediate issue, do backups of your database. Use a backup plugin (WP-DB-Backup is what I use, find it on the WP plugins repository) to handle this … Read more

Increment value (value = value+1) of $wpdb->update

You don’t. Not with the WPDB update() function. The update function assumes that the values of the columns are strings. You can override that with the format parameter, but that only allows %d, %f, and %s (integer, float, string). It doesn’t allow operations on columns like total+1. You’d have to use the query() function directly … Read more

Programmatically changing role information; editing role name and deleting

There’s a whole host of functions specifically for this purpose; http://codex.wordpress.org/Function_Reference#User_and_Author_Functions Of particular interest (but not limited to) are, add_cap add_role get_role map_meta_cap remove_cap remove_role As well as numerous other user related functions that will allow you to verify/validate their authority based upon your use-case scenario and so on. Looking in wp-includes/capabilities.php you we can … Read more

Is it useful to turn on MySQL query cache for performance

General speaking yes for read-only applications (until MySQL 5.7, it’s deprecated since version 8.0), it enables equal SELECTs to return data extremely fast if identical calls are already stored in cache. You should consider that: Only exact same clauses can benefit from the cache engine (no spaces, no comments, no actual differences in WHERE expressions); … Read more

Alternative to mysql_real_escape_string

When working with database in WordPress you should never use the low lever mysql_* or mysqli_* functions. Always use $wpdb methods, in your case you should use prepare(): $query = $wpdb->prepare( “SELECT post_title from $wpdb->posts WHERE post_title LIKE %s”, “%” . $myTitle . “%” ); Moreover, once you are getting a single column, you have … Read more

“#1067 – Invalid default value for ‘post_date'” when trying to reset AI after backup

The post_date default value is 0000-00-00 00:00:00. If you check the sql_mode variable like this: show variables like ‘sql_mode’; … it will show you the sql_mode variable, that will be sth like this: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION You have to set up again sql_mode variable without NO_ZERO_IN_DATE,NO_ZERO_DATE So in the previous example you should set the sql_mode like … Read more

How to disable `SQL_CALC_FOUND_ROWS` [duplicate]

First should only disable SQL_CALC_FOUND_ROWS if you aren’t using pagination, to do so set parameter no_found_rows to true in WP_Query. WP_Query( array( ‘no_found_rows’ => true ) ); Note get_posts() does that by default.