plugin development – Delete data from database using row action


I have little problem how implement deleting data from database using row actions. I have my custom list which includes data from database table.

 function column_name( $item ) {
    $delete_nonce = wp_create_nonce();
    $title="<strong>" . $item['article_name'] . '</strong>';
    $actions = [
        'edit' => sprintf('<a href="?page=%s&id=%s">Edit</a>', 'edytuj-artykul', $item['article_id']),
        'delete' => sprintf('<a href="?page=%s&action=%s&article_id=%s&_wpnonce=%s">Delete</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint($item['article_id']), $delete_nonce)
    return $title. $this->row_actions( $actions );

function delete_article($item){
    $article_id = $item['article_id'];
    global $wpdb;
     $wpdb->query("DELETE FROM $table WHERE article_id = %d", $article_id);

In the same file I added

add_action( 'admin_action_delete', 'delete_article' );

When I click Delete action, nothing happend. I got link

but record is not deleted from database.

For testing, I added a specific ID number of article to the delete_article method in the SQL query but still not works, so this method is not used by WP, when I click delete button.

Someone can give me any tip what am I doing wrong, because I spent on this few few hours 🙂

Best Regards,

in progress 0
BElluu 1 year 2021-09-04T16:49:24-05:00 0 Answer 0 views 0

Answer ( 1 )


    I think it’s better to use the $wpdb->delete() function to remove a row.

    $article_id = $item['article_id'];
    $table = 'wp_copywriter_articles';
    $wpdb->delete( $table, array( 'id' => $article_id ) );

Leave an answer