【发布时间】:2016-05-13 11:25:07
【问题描述】:
我正在尝试构建一个插件来管理 Wordpress 中的自定义表格。在这个插件中,我将编写 3 个函数。第一个从数据库中获取数据,如下面的屏幕截图所示。第二个功能是更新记录状态。最后一个功能是删除一条记录。
我的问题是我不知道如何将函数链接到操作列中的链接。 Wordpress 不允许我或者我不知道如何发送查询以删除或更新记录。
我希望如果我点击更新,我点击选择的记录的状态将被更改,然后重新加载页面。如果我单击删除然后重新加载页面,它将删除该记录。我可以编写函数但没有运气向它发送 ID 查询。
请帮忙。谢谢。
<?php
/*
Plugin Name: Manage Custom Table
Plugin URI: http://_adddress.com
Description: Testing Plugin
Author: XXXXXXXXXX
Version: 1.0
*/
require_once('functions/functions.php');
add_action('admin_menu','ManageCustomTable_admin_actions');
function ManageCustomTable_admin_actions() {
add_options_page('Manage Custom Table','Manage Custom Table','manage_options',__FILE__,'ManageCustomTable_admin');
}
function ManageCustomTable_admin(){
global $wpdb;
$data = $wpdb->get_results ("
SELECT
id,
school_id,
added_date,
campus_status
FROM
table_campus
");
?>
<style>.notice-warning {display:none;}</style>
<table class="widefat" style="margin:20px auto; width:97%;">
<thead>
<tr>
<th>ID</th>
<th>School ID</th>
<th>Added Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>School ID</th>
<th>Added Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
<?php
foreach ($data as $data) {
echo '<tr>';
echo '<td>'. $data->id.'</td>';
echo '<td>'. $data->school_id.'</td>';
echo '<td>'. $data->added_date.'</td>';
echo '<td>'. $data->campus_status.'</td>';
echo '<td>';
?>
<a href=#> Update </a>
<a href=#> Delete </a>
<?php
echo '</td></tr>';
}
?>
</tbody>
</table>
<?php
}
?>
【问题讨论】:
-
我知道如何处理表格。但是在wordpress仪表板中。这是行不通的。我无法向页面本身发送查询。
-
我在你的代码中没有看到
<form method='post'>? -
我已经试过了。但是这个查询被wordpress拒绝了,所以我把它拿出来了。
标签: php jquery mysql wordpress