我正在写一个Wordpress插件。有了这个插件,我更新了一些数据。查询和更新工作正常,但我的标题("location: url");
不起作用。如果我放置一个回声,它不会给出标题已经发送的任何错误。看起来它对这些线没有任何作用。我的代码......
<?php require_once('../../../wp-config.php');
$baanstatus_table=$wpdb->prefix . 'baanstatus';
$id = $_GET['id'];
$bijgewerkt =$_GET['bijgewerkt'];
$baanstatus= $_GET['baanstatus'];
$handicarts = $_GET['handicarts'];
$trolleys = $_GET['trolleys'];
$winterontheffing = $_GET['winterontheffing'];
$zomergreens = $_GET['zomergreens'];
$qualifying = $_GET['qualifying'];
$onderhoud_greens = $_GET['onderhoud_greens'];
$onderhoud_anders = $_GET['onderhoud_anders'];
$opmerkingen = $_GET['opmerkingen'];
global $wpdb;
$data_array =array('id' => $id,
'bijgewerkt' => $bijgewerkt,
'baanstatus' => $baanstatus,
'handicarts' => $handicarts,
'trolleys' => $trolleys,
'winterontheffing' =>$winterontheffing,
'zomergreens' =>$zomergreens,
'qualifying' =>$qualifying,
'onderhoud_greens' =>$onderhoud_greens,
'onderhoud_anders' =>$onderhoud_anders,
'opmerkingen' =>$opmerkingen
);
$where =array('id' => $id);
$wpdb->update( $baanstatus_table, $data_array, $where );
header("location:http://almeerderhout.fcklap.com/wp-admin/options-general.php?page=my-unique-identifier");
exit();
?>
答案 0 :(得分:3)
也许您应该尝试使用javascript而不是PHP位置。
<?php
echo '<script>location.href="http://almeerderhout.fcklap.com/wp-admin/options-general.php?page=my-unique-identifier";</script>';
?>
答案 1 :(得分:1)
以下代码可以帮助您
<?php
wp_redirect( $location, $status );
exit;
?>
上述wordpress函数将用于重定向Codex Link function reference
答案 2 :(得分:0)
您应该将插件挂接到正确的Wordpress操作上,以避免在尝试重定向时出现“标题已发送错误”。
我发现template_redirect
操作是执行重定向的一个好地方,因此您可以编写如下内容:
function do_something_then_redirect() {
// do something with $_GET or $_POST data
// then redirect to some url defined in the $redirect_url variable
wp_redirect($redirect_url);
die;
}
add_action('template_redirect', 'do_something_then_redirect');