php - How to get a wordpress post custom filed value and assign it to a variable? -


I am creating a form that sends the details of the form to my email.

My custom field is:

Enter image details here

My Function Php

  function getHotel_contact_number () {global $ wp_query; $ Postid = $ wp_query- & gt; Post- & gt; Id; $ GetHotel_contact_number = get_post_meta ($ postid, 'hotel_contact_number', true); $ GetHotel_contact_number; }   

and my form is:

  & lt; PHP $ errors = array (); If (isset ($ _ POST ["submit"])) {$ to = "myemail@email.com"; $ Theme = "this is my subject"; $ Hotels = meet (); $ Hotel_contact_nmbr = getHotel_contact_number (); Check out the $ header = array ('sender email'). '' & Gt; ';' // and make sure it is not a blank / empty string. If (empty ($ sender)) {// string down empty, Error Errors $ Error Adding $ Errors ['Sender User'] = "Please Enter Your Name!" If (empty ($ Sender Email)) {// empty string, error errors $ add errors $ errors ['Sender e-mail'] = "Please enter your email!" $} Mailbox D = "& lt; h3> Hotel details & lt; / h3 & gt; & lt; br / & gt; $ hotel & lt; br / & gt; $ hotel_contact_nmbr 
" $ Mail_sent = wp_mail ($ $ $ $ theme, $ mailbox, $ header);} if ($ mail_st) {? & Gt; & lt; h1 style = "color: # 007f00;" & gt; request sent. Lt; / h1 & gt; & lt ;? php} and {? & Gt; & lt; form id = "" name = "" action = "& lt ;? php echo get_permalink ();? & Gt; method = "Post">
'. $ Errors ['senderEmail']. '& Lt; / span & gt; ';}? & Gt; & lt; / div & gt; & lt; / div & gt; & lt; / div & gt; & lt; input type = "submit" value = "submit" name = " Submit "& gt; & lt; / form & gt; & lt ;? php}? & Gt;

But when the form is submitted, contact me at the hotel contact number For Val is getting blank value. Am I wrong? How can I get the right custom filed value if the form is submitted?

If I use hidden fields for it then it works fine Has been: As I mentioned, take a look at the lower area of ​​the question hidden field.

Change the function with the following code:

  function getHotel_contact_number () {global $ wp_query; $ Postid = $ wp_query- & gt; Post- & gt; Id; $ GetHotel_contact_number = get_post_meta ($ postid, 'hotel_contact_number', true); Refund $ getHotel_contact_number; }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -