Bulk Action in wp_list_table

时间:2021-01-11 作者:SF_IreSearch

我只想对delete函数执行批量操作。我在谷歌上研究了这么多例子,但还是做不到。如果有人能帮我解决这个问题,我将不胜感激。下面是我的代码。当选择并选择“在下拉列表中删除”并单击“应用”时,不会发生任何情况。

public function get_bulk_actions(){
    $action = array(
        "delete" =>"Delete"
    );
    return $action; 
}

public function get_columns(){
    $columns = array(
        "cb"=>"<input type=\'checkbox\'/>",
        "No"=>"No",
        "Name"=>"Name",
        "Email"=>"Email",
        "Unique_Code"=>"Unique Code",
        "Created_date"=>"Created Date"
    );
        return $columns;
 }

 public function column_cb($item){
    return sprintf(\'<input type="checkbox" name="post[]" value="%s"/>\',$item[\'id\'] );
 }

public function process_bulk_action() {

// If the delete bulk action is triggered
 $action = $this->current_action();
        if( \'delete\'===$action ) {
        $delete_ids = esc_sql( $_POST[\'post\'] );
        // loop over the array of record IDs and delete them
            foreach ( $delete_ids as $did ) {
                global $wpdb;
                $wpdb->query($wpdb->prepare( "DELETE FROM mncplugin WHERE id=\'".$did."\'"));
            }

                    wp_redirect( esc_url( add_query_arg() ) );
                    exit;
                    }
}

1 个回复
SO网友:Jeet Patel

包装您的->display() 变成一个form 标签,如下所示;

<form id="list-table-form" method="post">
 <?php $exampleListTable->display(); ?>
</form>
如果没有form 标签

相关推荐

在管理员帖子wp-list-table之前/之后添加内容

我知道有两个钩子可以在分类法wp列表前后添加内容。是否有操作可在编辑上的post type wp list表格后添加内容。php页面?$taxonomy列表:add_action( \'category\' . \'_pre_add_form\', \'copy_above_form\' ); function copy_above_form( $taxonomy ) { echo \'<p>Above the WP-List-Table</p>\';&#x