How to get INSERT errors from $wpdb?

To insert data you should use query() (documentation), get_var() method is for selecting data. If error is encountered, query() returns FALSE. query() This function returns an integer value indicating the number of rows affected/selected for SELECT, INSERT, DELETE, UPDATE, etc. For CREATE, ALTER, TRUNCATE and DROP SQL statements, (which affect whole tables instead of specific … Read more

WordPress insert query is not working : Showing no Error

There appears to be a syntax error on line 4. string is not quoted ↓ ↓ ↓ $sql = “CREATE TABLE IF NOT EXISTS ” . $wpdb->prefix.credofy_contact_form. ” ( Instead, I would recommend moving your table creation logic to a plugin and having it run off an installation hook. Below is an example: <?php /** … Read more

Update Custom Post Type Taxonomies with SQL

Why am I getting this error? Because the table wp_term_taxonomy does not have the column object_id. And the correct table that you should update is the wp_term_relationships table which does have the column object_id. See the WordPress database diagram and also the WordPress database description for more details. So your SQL query should be: UPDATE … Read more

Replace a character in all post titles and slugs

Slugs are saved in the very same table but in the post_name column. So your query would look like this: UPDATE wp_posts SET post_name = REPLACE(post_name, ‘m’ , ‘p’) WHERE post_type=”post” AND post_status=”publish”; By the way, I’d suggest you to use $wpdb->posts instead of just wp_posts ( then it would be compatible with different prefixes, … Read more

SQL syntax error. However, it works normally at phpmyadmin

) bracket missing in last condition. (i.e AND (b.meta_key = ‘usage_count’ AND b.meta_value=”0″”); ) $rowcount = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->postmeta AS a, $wpdb->postmeta AS b WHERE a.post_id = b.post_id AND (a.meta_key = ‘customer_email’ AND a.meta_value LIKE ‘%[email protected]%’) AND (b.meta_key = ‘usage_count’ AND b.meta_value=”0″)”); echo $rowcount;

Run Username SQL Query from WordPress Child Theme Functions File

There are many ways you can achieve this… In your instance, as you pointed out $wpdb, here is the possible ways you can achieve this: 1. Use $wpdb::query You can run this query directly using $wpdb’s query method as: add_action(“init”, “username_query”) function username_query(){ global $wpdb; $prefix = $wpdb->prefix; $query = “UPDATE `{$prefix}wp_users` SET `user_login`= ‘new-admin-name-here’ … Read more

Error missing MySQL extension

The solution to this will require server level changes, this isn’t something you can fix by changing PHP files. Your host needs to install the mysqli PHP extension

Match tag names with form titles

I don’t see PHP syntax errors (like unwanted brackets) in your code, but there are two WordPress-specific issues that need to be fixed: Note that wpdb::prepare() needs one or more placeholders (e.g. %s for strings and %d for numbers) and the replacement value for each placeholder. So in your case, the correct $wpdb->prepare() would be: … Read more

WordPress doesn’t save changes some times

You are mentioning the mysqldump, and it might be linked to the problem. If your mysqldump takes long time, and lock tables, it might cause the requests to your server when tryig to save posts, to time out. It could also just be a plugin that is messing something up, server-side settings that have errors … Read more