Delete rows

  $sql = $wpdb->prepare("DELETE FROM {$wpdb->prefix}tbl_my_table WHERE user_id = %d", $user_id);
  if (current_user_can('administrator'))
    $wpdb->show_errors();
  $wpdb->query($sql);

Delete based on DateTime

  //----- DELETE OLD EVENTS -----
  $sql = "DELETE FROM {$wpdb->prefix}my_table_name WHERE EventDateTime < DATE_SUB(now(), INTERVAL 90 DAY)";
  if (current_user_can('administrator'))
    $wpdb->show_errors();
  $wpdb->query($sql);

  //Also:
  //INTERVAL 1 MONTH
  //INTERVAL 1 HOUR
  //etc
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *