WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am just really confused how to do this, becouse I am newbie in wordpress. So what am trying to do:

I have a custom form on home page and posting form value by post method. Now I want to fetch meta value by the comparision of post value.

I am trying

$froms = get_post_meta( 139, 'from',true );
$tos = get_post_meta( 139, 'to',true ); 
if($froms=$from && $to=$tos) 
echo "test match";
echo "Not found";

Now for whatever value of $from its showing match found.

and if i tried to print_r($from) it always show Array([0]=>"test")

feel free to ask me if my question is unclear, how can i fetch meta value by some comparision of posted value..

I just want to check if my meta value and posted form value are same then echo "test match", if my posted value did not match with meta value then echo "not found"


share|improve this question
up vote 2 down vote accepted

Use the third parameter of the get_post_meta(). If the third parameter is set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields

for example:--

$froms = get_post_meta( 139, 'from', true );
$tos = get_post_meta( 139, 'to', true );

For more details look into the Codex here

share|improve this answer
Thanks Mohanty, for valuable knowledge now i am getting meta value without array, but why it is always showing "test match" while I am changing the form posting value.... – Dk-Macadamia Oct 21 '13 at 6:41
I cannot tell that until unless I look more into the code, I can see you are checking the values and if true echoing test match. – Maruti Mohanty Oct 21 '13 at 6:46
yes, and it always going true... – Dk-Macadamia Oct 21 '13 at 6:47
can you tell me what are you trying to accomplish and what do you think is going wrong here? – Maruti Mohanty Oct 21 '13 at 6:57
sir see my update, i just want to check meta value if they are same as posted value should perform some specific action..... – Dk-Macadamia Oct 21 '13 at 7:03

Your Answer


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.