【问题标题】:WordPress's wp_redirect() with add_query_arg() not updating global $_GET带有 add_query_arg() 的 WordPress wp_redirect() 未更新全局 $_GET
【发布时间】:2015-03-17 16:00:09
【问题描述】:

我访问该页面的方式如下:
example.com?step=3
到这里为止,它可以工作,如果我使用 $_GET['step'] 没问题,它是 3。

但是,在第 3 步之后做它需要做的事情,我打电话给:
wp_redirect( add_query_arg( 'step', 4 ) );
查看 Devtools 的网络选项卡,它确实使用 302 访问:example.com?step=4
但是在页面$_GET['step'] 仍然是3!比它进入一个无限循环。

我登录了$_SERVER['QUERY_STRING'],它与预期的一样step=4,但在下一行我调用$_GET['step'],它是3!

当我直接访问 example.com?step=4 时,$_GET['step'] 为 4,但当我使用 wp_redirect(); 时,它不起作用。

有人可以帮忙吗?

【问题讨论】:

    标签: php wordpress redirect query-string


    【解决方案1】:

    我认为您的问题是在添加新“步骤”之前您没有清除旧的“步骤”。 add_query_arg() 不会更新字符串,它会添加到它。

    所以尝试做类似...

    $origURL = remove_query_arg( 'step' );
    
    wp_redirect( add_query_arg( 'step', 4, $origURL ) );
    

    【讨论】:

      【解决方案2】:

      wp_redirect(esc_url(add_query_arg('step' => '4',$origURL)));

      【讨论】:

        猜你喜欢
        • 2016-10-21
        • 2018-04-16
        • 1970-01-01
        • 2019-11-30
        • 2016-01-10
        • 2014-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多