• dancingpony

    (@dancingpony)


    I’ve created a shortcode that houses a function to add a zip/postcode text field to a page. It’s inside a form and after you submit the form it should update_user_meta postcode and all is good.

    Everything is working fine if the shortcode is on a Post type, but if I put it on a ‘Page’ type, the form appears fine, but after clicking Update, I get the ‘Are you sure you want to do this?’ WordPress message.

    What is the difference between the Post and the Page?

    My code below:

    function user_extraprofile_func( $atts ){
     $user_id = get_current_user_id();
     if ( isset($_POST['postcode']) ) {
      update_user_meta( $user_id, 'postcode', $_POST['postcode'] );
     }
     $postcode = get_user_meta($user_id, 'postcode', true);
     return '
      <form method="POST" action="" id="extra-profile" >
       <div>Postcode: <input name="postcode" id="postcode" type="text" value="'.$postcode.'" maxlength="10" /><br /></div>
       <p><b>Important:</b> Due Date must be in "dd-mm-yyyy" format.</p>
       <input type="submit" value="Update" />
      </form>';
     }
    add_shortcode( 'user-extra-profile', 'user_extraprofile_func' );

    The main thing I’m asking it why it doesn’t work in a Page type, but does everywhere else.

    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘update_user_meta() not working in 'Page'’ is closed to new replies.