I am trying to delete rows from db and getting this error. I googled and tried all the possible solution still no luck. I also mentioned “global $wpdb” but dont know why getting this error.
<?php
if($_POST['array'])
{
global $wpdb;
$productArray = $_POST["array"];
$count = count($productArray);
$table_name = "wp_cause_woocommerce_product";
for( $i=0; $i < $count; $i++ ){
$wpdb->delete( $table_name, array( 'product_ID' => $productArray[$i] ), array( '%d' ) );
}
}
I think the issue is that you are not getting the WordPress functions.
Add this in to the top of your code.
If you change your project path make sure you update the path to wp-load.php.
If you will change your project path in future, you can try this
Hope this helps.
I just add the below lines on top of the page and its working. I had to relate the file with wp functionality thats it :