I am having trouble finding a good resource on using the $wpdb function.
I am trying to delete a row from a custom table named: eLearning_progress
$removefromdb = $wpdb->query("DELETE FROM eLearning_progress WHERE ID = '$user_id' AND module_id = '$singlecomparearrays_remove'" );
The row I would like to delete has the ID of ‘$user_id’ and the ‘module_id’ of ‘$singlecomparearrays_remove’.
I have also tried:
$removefromdb = $wpdb->query( "DELETE FROM eLearning_progress WHERE ID = ($user_id) AND module_id = ($singlecomparearrays_remove)" );
and then:
$removefromdb = $wpdb->query($wpdb->prepare("DELETE FROM eLearning_progress WHERE ID = %s AND module_id = %s", $user_id, $singlecomparearrays_remove));
Please try not to sigh too loudly at my attempts but I can’t find a good guide on using the DELETE command with variables in there too.
Any help is much appreciated.
Regards,
Alex
5 s
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 eLearning_progress
? Maybe you enhance the question to understand it much better.