title: delete row from wordpress custom table
body: <p>I am trying to read data from wordpress custom table. I created table and got data from it. Now I need to create link for every row from table and when I click on link it should delete only one row.</p>
  
  <pre><code>global $wpdb;
      $table_name = $wpdb-&gt;prefix . 'customtable';
      $sql = "SELECT * FROM $table_name";
      $check = $wpdb-&gt;get_results($sql);
      echo '&lt;div class="col-lg-2"&gt;';
  foreach ($check as $loc){
          echo $loc-&gt;row1;
          echo '&lt;br&gt;';
          echo '&lt;form action="" method="post" enctype="multipart/form-data"&gt;';
          echo '&lt;input type="submit" name="delete" value="Delete" /&gt;';
          echo '&lt;/form&gt;';
          echo '&lt;br&gt;';
  
      }
  
      echo '&lt;/div&gt;';
      if( isset( $_REQUEST['delete'] ))
  {
      $wpdb-&gt;delete( $table_name, [ 'id' =&gt; $loc-&gt;id] );
  }
  </code></pre>
  
  <p>Link is working but I can't delete specific row.</p>
  
  <p>I tried creating function delete</p>
  
  <pre><code>function delete($id){
      global $wpdb;
      $table_name = $wpdb-&gt;prefix . 'customtable';
       $wpdb-&gt;delete( $table_name, [ 'id' =&gt; $id] );
  
  }
  </code></pre>
  
  <p>and then outside of foreach loop I defined </p>
  
  <pre><code>if (isset($_REQUEST['delete'])){
          $this-&gt;delete($loc-&gt;id);
  
      }
  </code></pre>
  
  <p>but again only last row is deleted.</p>