2014-08-28 62 views
3

我会尝试下面的代码在wordpress admin中重定向。wp_redirect()函数在WP中不起作用管理员

if(isset($_POST['submit'])) 
    { 
wp_redirect('admin.php?page=job-creation'); 
} 

我也尝试的wp_redirect('admin.php?page=job-creation');代替

wp_safe_redirect('admin.php?page=job-creation'); 

header('location: admin.php?page=job-creation'); 

所有代码在本地主机工作正常。但它不能在线工作(www.example.com)。

帮助我的人。

回答

5

我认为这是针对你的web服务器配置的,你不能在代码中的每个地方使用头函数。 而不是使用的标头,使用此:

print('<script>window.location.href="admin.php?page=job-creation"</script>'); 

这是重定向到另一个页面的简单的JavaScript代码。

UPDATE

有关使用header访问this question

+0

谢谢。它的工作 – 2014-08-28 06:24:54

0

首先的更多信息,你应该总是exit您使用wp_redirect后。

其次,你应该指定一个绝对的URI。为此,请使用admin_url

if(isset($_POST['submit'])){ 
    wp_redirect(admin_url('admin.php?page=job-creation')); 
    exit; 
} 
+0

它不工作 – 2014-08-28 06:24:37

0

如果url正确,请尝试在重定向之前使用ob_start()函数。

+0

它不工作 – 2014-08-28 06:24:09

1

在必须激活的插件中使用此代码。

function callback($buffer) { 
    // modify buffer here, and then return the updated code 
    return $buffer; 
} 

function buffer_start() { 
    ob_start("callback"); 
} 

function buffer_end() { 
    ob_end_flush(); 
} 

add_action('init', 'buffer_start'); 
add_action('wp_footer', 'buffer_end'); 
+1

我不知道这是如何回答这个问题... – 2015-04-21 13:26:27

+0

我已经得到了解决方案。那么为什么你在这里待了很长时间后才回答。 :) – 2015-04-24 11:57:05

+0

这个答案支持OP作为一个技巧。 – 2017-04-08 17:42:50