How can I link to another WordPress page but move variables to it as well (preferably not through the address bar)?
For instance, I have on one page a list of shops in which a user should be able to click on a shop, which would then open the shop page with the correct data.
So the shop's id needs to move from the shops list page to the shop page.


you could POST the shop id to the target page. otherwise- cookie, session. or just fetch it on the list page via ajax.

edit - a simple post request via a form:

in your source page:

<form action="b.php" method="post">
    <input type="hidden" name="id" value="42" />
    <input type="submit" />

in the target page b.php:

if( isset($_POST['id']) ):
    echo $_POST['id'];
  • Can you elaborate on the latter? I need to pass the shop ID from the list page to the shop page. How would I do it with ajax? – Ash Aug 4 '11 at 20:48
  • Not via ajax, I was suggesting not taking the viewer to another page and just fetching the contents of the shop page for the selected shop via ajax and displaying it on the list of shops page. – Milo Aug 4 '11 at 21:00
  • I see. So if I do want to open the shop on a different page my only two options are posting variables through the address bar and using cookies? – Ash Aug 4 '11 at 21:14
  • passing variables via the address bar is a GET request, ie: page?myvar=foo. a POST request passes the variable in a way that's hidden to the viewer and shows the plain URL. or a cookie. – Milo Aug 4 '11 at 21:35
  • Can you please give an example for using the post method? – Ash Aug 4 '11 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.