I’m trying to pass data between two WordPress posts via POST method from a form/link. However, the second post does not seem to be able to grab the POST data. I’m wondering if it has anything to do with my permalink structure which has no filenames, only directory paths.
Page 1 uses the following form to “link” to page 2 while sending data through a hidden field via POST Method:
<form name="offer" action="http://themotoroilevaluator.com/members-blog/motor-oil-bible-special-offer/" method="post" style="padding: 0px; margin: 0px;">
<input type="hidden" name="discount" value="yes">
<INPUT TYPE="image" SRC="/members-blog/wp-content/uploads/2011/12/special-offer.png" HEIGHT="350" WIDTH="550" BORDER="0" ALT="Discount Plus Additional Special Bonus Downloads - Click Here">
</form>
Then, on page 2 I have the following php code which is supposed to grab the data from that hidden field from the POST array:
$discount = $_POST['discount'];
Should be simple enough, but it’s not working. I tried placing the exact same code on a standalone php page and had the form post to that page as the “action”, and it worked fine. What do I need to do to get this to work in WordPress?
echoing $discount or $_POST[‘discount’] yields nothing and print_r($_POST) yields an empty array. Any thoughts?
You need to register the query var so it doesn’t get stripped by WP. Add this to your functions.php file.
To call this in your template, simply use the following: