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

How can I add/update post meta in a admin menu page?

You will need to use an Ajax function. Which requires javascript to send the form data to your php Ajax function which you can use to run update_post_meta();

Example:

Form Html:

<form>
<input id="meta" type ="text" name="2344" value="<?php echo esc_html( get_post_meta( 2344, '_your_key', true) ); ?>" />
</form>

Javascript:

jQuery(document).ready(function() {
    jQuery("form").submit(function() {
    var post_meta = jQuery("input name=[2344]").val();
    var ID = jQuery(this).attr("name");

    jQuery.ajax({
           type: "POST",
           url: ajaxurl,
           data: {
           action: "update_meta",
           post_id: ID,
           meta: post_meta,
          },
        success: function( data ) {
          //do something
     }
   });
 return false;

});

PHP function:

add_action( 'wp_ajax_update_meta', 'my_function' );
function my_function() {
   $post_id = $_POST['post_id'];
   $meta = $_POST['post_meta'];

  update_post_meta( $post_id, '_your_key', $meta );

  echo 'Meta Updated';
  die();
}

Related Posts:

  1. Can I exclude a post by meta key using pre_get_posts function?
  2. What is the index [0] for on post meta fields?
  3. Best way to programmatically remove a category/term from a post
  4. Custom field metabox not showing in back-end
  5. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  6. How to hide meta box values from custom fields list?
  7. What is the advantage of the wp_options design pattern?
  8. Storing meta fields multiple times OR once with multi dimensional array?
  9. display specific custom fields
  10. Meta keywords and descriptions plugin for manually editing meta for each page/post
  11. Is it possible to store arrays in a custom field?
  12. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  13. Transients vs CRON +Custom Fields: Caching Data Per Post
  14. Unable to save datetime custom meta field using update_post_meta() function
  15. Create custom field on post draft or publish?
  16. Display info from custom fields in all images’ HTML
  17. get_post_meta fields don’t show up on posts page
  18. Update meta values with AJAX
  19. copy attachments to another post type and change attachment url
  20. Cannot edit post meta fields with rest API
  21. Add a post meta key and value only if it does not exist on the post
  22. Order posts according to user defined order for meta values?
  23. Custom fields to save multiple values
  24. Function to change meta value in database for each post
  25. Get aggregate list of all custom fields for entire blog
  26. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  27. using multiple meta_key and meta_value in query_posts
  28. Adding custom fields (post meta) before/during wp_insert_post()
  29. MySQL Query that looks for post with Custom Field, then changes Category
  30. ACF: How to get the full field name (meta_key) by a field key?
  31. post meta getting deleted on save
  32. How to show a gloabl message on a user profile page (in back end)?
  33. filtering custom post types via meta data drop down
  34. How to add a new meta key and assign timestamp to posts
  35. Custom field not updating when value is empty
  36. meta_compare seems to be treating values as strings instead of integers as expected
  37. Calling the “wp-link-wrap” pop-up modal
  38. Limit the number of acf content when displaying in post loop [closed]
  39. Read / Watch / Listen times – meta
  40. How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
  41. How do I Implement Atomic Update of Post Metadata?
  42. How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
  43. Why is my Custom Meta Box Field Inputs NOT saving?
  44. Get registered custom fields or post meta even if empty
  45. Displaying multiple URLs as custom field values
  46. Show values of custom post meta on ‘Add new post’ page?
  47. Custom post meta field effect on the performance on the post
  48. Custom WP_Query for WordPress Search Results with meta_query
  49. How can you include custom post meta in search without calling each key?
  50. Unique meta_key with array value vs repeated meta_key with single values
  51. Can I access a post meta field before the loop?
  52. wrap text around custom fields array
  53. Allow only one post with specific meta value
  54. Get all the posts where meta field with multiple choice has several values checked
  55. wordpress custom loop ascending descending posts by custom field
  56. How to validate select field in post meta?
  57. How to display childrens custom fields?
  58. how to display custom fields of post on a web page
  59. Hide custom fields when empty
  60. How do I query the title (or handle?) of post meta fieldset (created with Simple Fields Plugin)
  61. Save all the post tags inside a custom field
  62. How to fill custom fields with brackets in their key with add_post_meta()?
  63. How add multiple wp_editor_box to new post
  64. Update post meta custom field using block editor
  65. Get custom fields without _edit_last, _edit_lock, _wp_page_template and _visual-subtitle
  66. Get YouTube video id from url in a custom field
  67. Related query shows same image in loop
  68. Why am I getting a “Call to member function format() on a non-object” error?
  69. Can’t Output get_post_meta?
  70. put saved metabox values back into fields and then display on the front end
  71. Modify custom field from front end
  72. How to get custom image field of specific post id
  73. get_post_custom_values problem, please help
  74. wordpress multi user question
  75. How can I change author of posts to the value of one of the custom field of the posts?
  76. Custom meta fields and meta keys
  77. Adding Custom Metadata to my Archive/Posts page
  78. How to improve my non-unique metadata MySQL entries?
  79. Saving Custom Field that includes Quotation marks
  80. Post meta data not showing in frontend, until hitting ‘update’ button
  81. searching by keywords in post’s metas or pagination links problem
  82. open modal window
  83. How do I update custom field post meta in frontend post template?
  84. update meta field value after
  85. Custom Fields Not Working In Footer
  86. Query Posts based on custom field value
  87. Echo out custom fields in comments
  88. Search one custom field?
  89. Can’t save meta field value if the title not set
  90. Display Data From This Custom Media Upload Meta Box?
  91. Save values generated via API as custom meta fields
  92. update_post_meta not working in action hook
  93. Display meta data from a custom field within plugin Category Grid View Gallery
  94. Hard Define Custom Field Value
  95. How do i output images from URL’s added to the same custom field key
  96. add multiple values (array) to post meta_input
  97. save all acf options in one meta_value [closed]
  98. WP Query Args – search by meta_key or title
  99. Search for meta_query does not return any result if combined with title
  100. Block Editor – Meta values not saved, meta changes to empty array on update
Categories custom-field Tags add-menu-page, admin-menu, custom-field, post-meta
Custom Text in Media Uploader in a Theme Options Page
Category List with custom urls

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