Keep custom GET parameters over POST request in WordPress

I need to keep my custom get parameter over ANY form submit in 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.

I even added ?foo=bar to action=’post.php’ and still nothing. I also added foo to 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.

Related posts

1 comment

  1. 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:

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

    It looks a bit ugly, but it’ll repeat any _GET parameters into the action.

    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. (It’ll always look like it’s one behind, but if you look at the html it’ll be right).

    Final note: All parameters sent via get, post and/or cookie, are available in $_REQUEST.

Comments are closed.