I am trying to add post-meta value and after this update query and after this get_post_meta value . but add_post_meta does not work .

<?php add_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>
  <?php update_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year'])); ?>

echo $year=get_post_meta($post_id , 'Product_Year',true );
  • you can value GET or not in $post_id? – Jignesh Patel Aug 2 '17 at 8:57

Add last parameter, refer this https://codex.wordpress.org/Function_Reference/add_post_meta

add_post_meta($post_id, 'Product_Year', trim( $_POST['Product_Year']), true);
  • this is not working right now @ any other help@ how can i insert form field input value in database – sanjay Aug 2 '17 at 8:56

You dont need to use add_post_meta and update_post_meta for same meta_key.

You can simply use update_post_meta function and this will add if the meta_key does not exist and will update if meta_key exists.

  • Yes@ good, but let me know how can work on edit module – sanjay Aug 2 '17 at 9:00
  • Please clarify more. – Aftab Aug 3 '17 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.