How to use $wpdb to delete in a custom table

The best WP API solution for this goal is to use the delete() function to remove a row. A small example, to delete the raw ‘ID’ in the custom table ‘eLearning_progress.’ $id = 0815; $table=”eLearning_progress”; $wpdb->delete( $table, array( ‘id’ => $id ) ); But I can’t see which raw you will delete in your table … Read more

How do I check for a duplicate record before inserting using wpdb

Let’s say the primary key of the table is my_part_ID. So we will check if there is any primary key value for the combination of user_ID and PL_part_ID as below $my_part_ID = $wpdb->get_var( $wpdb->prepare( “SELECT my_part_ID FROM ” . $wpdb->prefix . “pl_my_parts WHERE user_ID = %d AND PL_part_ID = %d LIMIT 1”, $user_ID, $PL_part_ID ) … Read more

Fetch array with $wpdb

wpdb‘s get_results method takes an optional second argument that lets you specify how the data is returned. The default return is an object. But you can also set it to… OBJECT – result will be output as a numerically indexed array of row objects. OBJECT_K – result will be output as an associative array of … Read more

Why $wpdb->show_errors() and print_error() is showing an output even if the query output is correct?

The output that you posted above is expected behaviour for $wpdb->print_error() if the following is true – You are running a single site, not multisite $wpdb->suppress_errors is set to false $wpdb->show_errors is set to false From the looks of your code, you meet all those conditions. Note also that, unless you have turned them off … Read more