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.
1 Answer
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" />
</form>
in the target page b.php:
<?php
if( isset($_POST['id']) ):
echo $_POST['id'];
endif;
-
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?– AshAug 4, 2011 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.– MiloAug 4, 2011 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?– AshAug 4, 2011 at 21:14
-
passing variables via the address bar is a
GET
request, ie:page?myvar=foo
. aPOST
request passes the variable in a way that's hidden to the viewer and shows the plain URL. or a cookie.– MiloAug 4, 2011 at 21:35 -