简体   繁体   English

在WordPress中保留自定义GET参数超过POST请求

[英]Keep custom GET parameters over POST request in WordPress

I need to keep my custom get parameter over ANY form submit in WordPress. 我需要将自定义get参数保留在WordPress中提交的任何表单上。 For instance, I have post edit like /wp-admin/post.php?post=493&action=edit&foo=bar Then I click update and gone, there's no foo in url. 例如,我有像/wp-admin/post.php?post=493&action=edit&foo=bar这样的帖子编辑然后我点击更新并且消失了,网址中没有foo。

I even added ?foo=bar to action='post.php' and still nothing. 我甚至添加了?foo = bar to action ='post.php',但仍然没有。 I also added foo to public query_vars . 我还将foo添加到public query_vars。 I searched a lot and found nothing related to this problem. 我搜索了很多,发现没有任何与此问题有关的内容。 Is there a way to do what I want? 有办法做我想要的吗? I can use javascript/jquery to manipulate the forms. 我可以使用javascript / jquery来操作表单。

I see that you've solved the issue using $_SESSION however for anyone else that needs this sort of functionality and can't use the session for any reason, this is also an option: 我看到你已经使用$_SESSION解决了这个问题但是对于任何需要这种功能并且因任何原因无法使用会话的人来说,这也是一个选项:

<form action="post.php?<?= http_build_query($_GET); ?>">

It looks a bit ugly, but it'll repeat any _GET parameters into the action. 它看起来有点难看,但它会在动作中重复任何_GET参数。

To test, I made this slightly awful way of tacking everything together: 为了测试,我做了一个非常糟糕的方法来解决所有问题:

<form method="post" action="?<?= http_build_query($_GET);?>&<?= http_build_query($_POST);?>">
    <label> Test<input name="<?= time() ?>"></label>
</form>

Note: You have to submit a few times before it starts appearing in the url as first submission is in POST , which is then added to the GET in the second post. 注意:在第一次提交处于POST ,您必须先提交几次才会开始显示在网址中,然后在第二篇文章中将其添加到GET中。 (It'll always look like it's one behind, but if you look at the html it'll be right). (它总是看起来像是一个落后,但如果你看看html它会是正确的)。

Final note: All parameters sent via get, post and/or cookie , are available in $_REQUEST . 最后注释:通过get,post和/或cookie发送的所有参数都可以在$_REQUEST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM