Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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;
share|improve this answer
    
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
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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