Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

update_post_meta after form is submited

The following is a crude example, it can be improved to ensure you’re dealing with integers etc and also shortened overall for brevity but this should get you started.

add_filter('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){

    global $post;

    if($form_id == 7){ //change 7 to the ID of your form

      $previous_value = get_post_meta($post_id, $key, true); 

      if($previous_value == null) {

        $value = 12345; //this is a starting value if nothing set
        $previous_value = $value;
        $value = $previous_value - 1; //returns 12344

      } else {

        $value = $previous_value - 1; //returns whatever previous value was - 1 

     }

      update_post_meta($post->ID, $key, $value, $previous_value);

    }
}

I’m making some assumptions without knowing if you are working with a starting value or not, but this should get you going in the right direction.

Related Posts:

  1. Add options to featured image
  2. Change meta tags programatically
  3. Use a function to update post meta based on other post meta
  4. update_post_meta for custom field not working upon form submission
  5. Assign category using custom field?
  6. Convert User ID’s to User Names in a single.php file
  7. Can’t check if a post has thumbnail adding filter to get_post_metadata()
  8. Move Post to different category if post_meta field is 0 or is 2 days old?
  9. What WordPress function to use to get meta value by using meta keys?
  10. Default Custom Field Value Automatically Update
  11. Post meta not updating
  12. Function to update post_meta based on existing post_meta
  13. Exclude from the query posts with meta_key and meta_value
  14. Prevent custom field from being updated after first publish
  15. Get array of metakey in all posts
  16. User function to return multiple get_post_meta()
  17. What are the meta fields for an attachment?
  18. How to avoid saving empty data to sql while using add_meta_box
  19. How to change text color depending on the number value (Using javascript)
  20. How to add custom metakey to shop_order page’s searching function?
  21. Update wp_postmeta table based on 2 keys
  22. blank page with wp_get_attachment
  23. Reference multiple style sheets, clearing styles for permalink page, custom fields for css
  24. How To Display Author Popup on Entry Meta (Genesis Framework)?
  25. Creating a “Related Meta” type field?
  26. Remove post from latest posts after a month only with certain tag
  27. save_post doesn’t correctly process function call with php class
  28. Return ACF Field value function
  29. update_post_meta not working in function
  30. How To Get WordPress Categories Last Update Date?
  31. How to add a meta information to the URL?
  32. Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
  33. Add custom fields after post/page title
  34. Display post_meta-by_key on product catalogue
  35. How to save custom made object in an array in a post meta field
  36. Adding and updating repeating custom field meta data
  37. Missing feature image link function
  38. What’s the difference between home_url() and site_url()
  39. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  40. get_template_directory_uri pointing to parent theme not child theme
  41. How to customize the_archive_title()?
  42. remove empty paragraphs from the_content?
  43. What is the “with_front” rewrite key?
  44. Why use if function_exists?
  45. How to override parent functions in child themes?
  46. wp_enqueue_script was called incorrectly
  47. Add multiple custom fields to the general settings page
  48. Ajax call always returns 0
  49. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  50. How long does a deprecated function live in core?
  51. Solution to render Shortcodes in Admin Editor
  52. How to add a data attribute to a WordPress menu item
  53. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  54. remove_action on after_setup_theme not working from child theme
  55. plugins_url vs plugin_dir_url
  56. Remove type attribute from script and style tags added by WordPress
  57. How to run a function every 5 minutes?
  58. Best way of passing PHP variable between partials?
  59. Upload Multiple Files With media_handle_upload
  60. How to display custom field in woocommerce orders in admin panel?
  61. Adding fields to the “Add New User” screen in the dashboard
  62. Issues with title-tag and document_title_parts
  63. How do I get the current edit page ID in the admin?
  64. How to check if a user exists by a given id
  65. Why isn’t is_page working when I put it in the functions.php file?
  66. Add tags to the section via functions.php
  67. Add image size if page template
  68. How to create a custom order status in woocommerce!
  69. Remove Actions/Filters added via Anonymous Functions
  70. Adding a second email address to a completed order in WooCommerce [closed]
  71. How to load parent_theme functions.php before child_theme?
  72. How to load scripts/styles specific for a page
  73. Programatically add options to “add new” custom field dropdown
  74. Is there any global functions.php file which works for any theme?
  75. Excluding iPad from wp_is_mobile
  76. When should you, and when should you not, use wp_list_pluck()?
  77. Get the ID of the page a menu item links to?
  78. Add container to nav_menu sub menu
  79. Difference between the_permalink() and get_permalink() function
  80. What’s the difference between WordPress random_int() and PHP built-in function random_int()?
  81. Child theme – Overriding ‘require_once’ in functions.php
  82. Link to user’s profile settings page?
  83. WordPress Enqueue for homepage only, functions.php, wp-framework
  84. get php variable from functions php and echo it in theme template files [closed]
  85. Get menu object from theme_location
  86. Is it ok to use a function to output the text domain name in a wordpress theme
  87. Displaying the number of updates available in the Admin area
  88. Trying to use add_action and do_action with parameters
  89. Use AJAX in shortcode
  90. Set JPEG compression for specific custom image sizes
  91. Can the new 4.8v text widget visual editor be removed?
  92. Prevent “main” WPMU site_url() being returned in functions
  93. Include files in child theme functions file
  94. Memorizing syntax
  95. Custom page with variables in url. Nice url with add_rewrite_rule
  96. Define page template in wp_insert_post
  97. Which WP functions do you need to use esc_html() or esc_url() on?
  98. Check if post is being published for the first time, or is an already published post being updated
  99. Display random categories on the front page (Finding and Editing Theme Functions)
  100. How to redirect to post if search results only returns one post
Categories functions Tags functions, post-meta
Hard Define Custom Field Value
Pass WP post content to a jQuery plugin (Fancybox)

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress