Php – how to use $_POST in wordpress


Hey i am trying to retrive data from a basic form .. but when i am using $_POST['field name'] then it gives me nothing .

here is my basic code

form page is:


Template Name: galaxy

get_header(); ?>

<div id="main-content" class="main-content">

<form action="<?php echo site_url();?>?page_id=8" method="post">
<input type="text" name="name"  /> <input type="submit" value="Send"  />


</div><!-- #main-content -->


when i click submit it redirects to next page but display nothing with this code


Template Name: get_value_galaxy

echo $name;



Best Solution

Try using a different name for the variable. I know that Wordpress uses "name" as a public query var, and perhaps that's why it's not working. So rather than using name="name", try this:


<input type="text" name="unique_name" />

Post Page:

echo $name;

See this list for all query vars: