Wordpress 删除 table 中的行

Wordpress delete row in a table

我正在我的 wordpress 网站上制作一个管理插件。我正在尝试在我的 table 行中添加一些删除功能。我的 table 在 foreach 循环中

 $edteams = $wpdb->get_results(" //some sql query ");

foreach ($edteams as $row) {

        echo "<tr><form class='form' action='' method='post'>";
        echo "<td>$row->team_id</td>";
        echo "<td>$row->team_name</td>";  
        echo "<td><input class='input' type='text' name='won' value='$row->games_won'> </td>";
        echo "<td><input class='input' type='text' name='lost' value='$row->games_lost'> </td>";
        echo "<td><input class='input' type='text' name='pct' value='$row->game_pct'></td>"; 
        echo "<td><input class='input' type='text' name='streak' value='$row->winning_streak'></td>";
        echo "<td><button class='btn btn-default' name='update'><span class='glyphicon glyphicon glyphicon-edit'></span></button>
            <button class='btn btn-default' name='delete' value='$row->team_id'><span class='glyphicon glyphicon-trash'></span></button></td>";
        echo "</tr>"; 
        echo "<input type='hidden' id='team_id' value='$row->team_id'/>";
        }   

这是我的删除代码

if(isset($_POST['delete'])) 
                 {

                    echo "<script>alert('Your account is now deleted'); </script>";
                        $id = $wpdb->get_results("SELECT a.team_id, a.team_name, a.program_id ,b.games_won, b.games_lost, b.game_pct, b.winning_streak
                                FROM  program_teams as a
                                INNER JOIN program_team_standings as b
                                ON a.team_id=b.team_id");    
                    foreach ($id as $row) {
                        echo $id = $row->team_id;
                }
                 echo "<script>alert('Your account is now deleted'); </script>";
                        $wpdb->delete( 'program_teams', array( 'team_id' => $id ) );
                        $wpdb->delete( 'program_team_standings', array( 'team_id' => $id ));

当我点击删除按钮时,这段代码不起作用,它只是在我的管理页面上重定向,就像什么都没发生一样。

试试这个。

改变

 echo "<tr><form class='form' action='' method='post'>";

echo "<tr><form class='form' action='get_permalink()?page=page_slug' method='post'>";

代码段落添加

global $wpdb;