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

Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)

You did some mistakes that I have described below:

  • First thing you have placed jQuery Ajax code on the wrong place.
  • On ajax callback function variable name mashup like $post_id defined and used on update time $post_ID; PHP is case sensitive so it considers 2 different variables.
  • In some places, not closed } brackets.

Here is the right code which I have modified in your code.
Check this and let me know it’s work for you or not.
I have tested it works for me.

<?php /*Register the Menu*/ 
add_action( 'admin_menu', 'ews_metas_add_admin_page');
function ews_metas_add_admin_page() { 
// Adds plugin page to menu
add_menu_page ('Effective Web Solutions Metas Descriptions', 'EWS Metas', 'manage_options', 'ews_meta_options_stephen_version', 'ews_meta_page_creation_stephen', get_template_directory_uri() . '/images/admin-ico-gray.png', 110 );
} 

/*Page Html Render*/
function ews_meta_page_creation_stephen() { ?>
<div>
<?php settings_errors(); ?>
<form method="post">
    <input id="meta" class="testing" type="text" name="2316" value="<?php echo esc_html( get_post_meta( 4189, '_metadescs', true ) ); ?>" />
    <?php submit_button();?>
</form>
</div>
<script>
jQuery(document).ready( function($){ 
jQuery(".toplevel_page_ews_meta_options_stephen_version form").submit(function() {
        var post_meta = jQuery("input.testing").val();
        var post_ID = jQuery("input.testing").attr("name");
        jQuery.ajax({
            type: "POST",
            url: 'https://dev.ewsproduction.com/dev6/ewstheme/wp-admin/admin-ajax.php',
            data: {
                action: "update_meta_descriptions",
                post_id: post_ID,
                post_meta: post_meta,
            },
            success: function( data ) {
            //do something
            console.log('It worked!');
        }
    });
    return false;
    });
});
</script>
<?php }

/*Update the meta using Ajax request */
add_action( 'wp_ajax_update_meta_descriptions', 'update_meta_descriptions' );
function update_meta_descriptions() {
  global $wpdb;
  $post_id = $_POST['post_id'];
  $meta = $_POST['post_meta'];
  $details = update_post_meta( $post_id, '_metadescs', $meta );
  echo 'Meta Updated';
  die();
}?>

Related Posts:

  1. Save metabox with multiple checkbox array
  2. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  3. Ordering posts by metadata
  4. Saving value of a selection option in comment form as comment meta
  5. How to get Metabox custom field to show checked if value is updated using post meta query?
  6. Run Shortcode of post’s custom field in functions.php / Plugin
  7. Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
  8. Ajax is not working in a loop
  9. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  10. Any way to update_post_meta with html content? It gets stripped and becomes empty
  11. Displaying Custom Post Meta
  12. update_post_meta not working in a loop
  13. Create custom HTML/JS app inside page
  14. Use just a shortcode from another page
  15. Get draggable widgets on Edit Post page
  16. template_redirect or admin-ajax.php?
  17. Custom code for WordPress dynamic menu
  18. how to get context information inside my funcion
  19. Custom fields for custom post type
  20. AJAX form post returns 0
  21. Update Data parameter of a wp_localize_script() call
  22. Checked() function on a multidimensional array
  23. jquery & ajax sending data to php
  24. wp_localize_script is not adding a global variable for javascript
  25. What is the best way to store a few fields?
  26. Delist entries in the_loop
  27. Custom post type’s extra fields – how to handle?
  28. Can’t get AJAX call working in custom plugin
  29. Bad Request in AJAX
  30. 400 Bad Request, in wordpress theme development, wp_ajax
  31. How can I add a simple custom field to my plugin?
  32. ajax recursive calls on wordpress returning answers outsite the function scope
  33. Ajax submit result opens in admin-ajax.php
  34. Are there any security risks when submitting data-attribute data through AJAX?
  35. insert query on a custom table using ajax with jQuery plugin Jeditable
  36. How to get error object returned by wp_create_user
  37. Plugin AJAX Save to Custom Table
  38. WP nonce field checkbox prints checked=’checked’ outside input field
  39. Data not insert and update through ajax and jQuery in admin page?
  40. Setting a JSON web token from a secondary api as a secure cookie on WordPress
  41. WP ajax requests not stacking?
  42. How to save post meta as an array in Gutenberg?
  43. How do I get rid of my inclusion race-condition on wp_enqueue_script
  44. per blog metadata for plugin
  45. AJAX button with success callback. (Titan Framework)
  46. ajax working when function is on child theme but not in plugin page
  47. AJAX call to admin-ajax.php by subscriber returns home page
  48. How to format custom fields when editing an attachment?
  49. AJAX call returns ‘testtest0’ instead of ‘test’ – why?
  50. Using delete_post_meta for deleting multiple selected options
  51. Ajax function is not working on WordPress
  52. About a programming language starts with [closed]
  53. Best practice for plugin: always detect admin-ajax call?
  54. add_action wp_ajax_ not loading in plugin file WP Network
  55. Why is the form not updating when I select a new sector from the list?
  56. Get audio metadata on file upload
  57. Workflow for new importer plugin – your advices?
  58. Plugin Form Submitting to admin-ajax.php instead of admin-post.php
  59. Plugin can’t be activated [closed]
  60. Ajax +wordpress onClick link redirect to new page and create html content
  61. AJAX request not routing through proxy
  62. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  63. Is there a way to add a link with add_post_meta?
  64. Adjust query on single
  65. Get cat parameter from admin-ajax
  66. how to add custom fields into new & update post page?
  67. Customise Grouped Product display in Woocommerce with custom column
  68. WordPress (pagenow link) in ajaxurl change after i change plugin language
  69. Why is $_POST empty when saving custom Meta Box?
  70. Ajax on the Administration Side of plugin – returns 0
  71. How to do admin ajax request in a plugin for rest api
  72. Ajax action has 200 status but response of No response data available for this request
  73. Jquery php request is returning a weird result
  74. WordPress Does not grab the string sends useing AJAX response, wp_ajax hook
  75. Posts form with AJAX request – Plugin development
  76. Condition to check previous next article post title
  77. GET request return value as error instead of success
  78. How to control ajax calls without effecting memory of server?
  79. Bad request 400 using class based files
  80. register_meta not showing custom post type metabox data in rest api
  81. Forbidden Error in ajax call with wordpress
  82. Trying to run a Ajax request from a checkout form in woocommerce via a custom plugin
  83. “add to cart” links css class “ajax_add_to_cart” doesn’t show in woocommerce in widget sidebar
  84. ajax stopped working when not logged in wordpress
  85. WP_Query not ordering correctly
  86. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  87. ajax call return 406 not acceptable for non logged users only
  88. Does $this context change in an AJAX callback?
  89. Adding customs fields on each product on the cart
  90. Insert, update or remove data from database (usermeta)
  91. ajax response strips multidimensional array and unable to decode
  92. 400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true
  93. Rate limiting ajax requests in WordPress
  94. WordPress Ajax not returning Response
  95. ajax-action.php can’t find added action
  96. Using AJAX to submit and return data inside the WordPress Plugin Boiler Plate framework
  97. AJAX call of function containing javascript which is not loaded (Plugin development)
  98. Performing ajax request in wordpress
  99. Inserted data from database does not showing on front-page without referesh page?
  100. add_meta_box does not display meta box in Admin
Categories plugin-development Tags ajax, custom-field, plugin-development, post-meta
How to use different domains subdomains in WP multisite? [duplicate]
How to add fields in the WordPress editor?

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