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

change attachment custom field onChange event

Replace the function into your functions.php file –

function update_dynamic_select() { 

 update_post_meta($_POST['aid'], $_POST['field'], $_POST['value']);

echo  $_POST['value'];

die();
}

Replace options in your HTML part –

<?php
$val = get_post_meta( 104, '_image_matmenys', true );

$s1 = ($val == "10x10") ? 'selected="selected"' : '';

$s2 = ($val == "20x20") ? 'selected="selected"' : '';

$s3 = ($val == "30x30") ? 'selected="selected"' : '';

?>

<option value="10x10" <?php echo $s1;?>>10x10</option>

<option value="20x20" <?php echo $s2;?>>20x20</option>

<option value="30x30" <?php echo $s3;?>>30x30</option>

EDIT:

Also, add one more hook –

add_action( 'wp_ajax_nopriv_dynselect', 'update_dynamic_select' );

and make sure that variable ajaxurl has value admin_url('admin-ajax.php') i.e. var ajaxurl="<?php echo admin_url("admin-ajax.php");?>"

Related Posts:

  1. Update meta values with AJAX
  2. Is there any action filter/hook for validating a custom field before publishing the post?
  3. Get updated meta data after save_post hook
  4. post meta data clearing on autosave
  5. Display info from custom fields in all images’ HTML
  6. Using custom fields in a filter hook
  7. filtering custom post types via meta data drop down
  8. How to display childrens custom fields?
  9. Footnotes in custom fields
  10. Set new url from custom post field
  11. Can I exclude a post by meta key using pre_get_posts function?
  12. Is there a way to set default custom fields when creating a post?
  13. What is the index [0] for on post meta fields?
  14. Custom field metabox not showing in back-end
  15. So much data in postmeta
  16. Pass all custom fields through the same filter on post load?
  17. How to hide meta box values from custom fields list?
  18. get_post_meta() unserialize issue – returns boolean(false)
  19. What is the advantage of the wp_options design pattern?
  20. Edit Custom Database Tables in WordPress
  21. Meta keywords and descriptions plugin for manually editing meta for each page/post
  22. Up/Down voting system for WordPress
  23. Change content before writing to database
  24. WordPress Search Custom Meta Field Only
  25. Front-end update_post_meta with ajax
  26. Add an advert every nth Paragraph
  27. Custom fields to save multiple values
  28. Use ajax to update_post_meta
  29. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  30. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  31. Saving custom image meta fields
  32. Saving custom profile fields
  33. Get all meta keys assigned to a post type
  34. Update posts after populating ACF field value [closed]
  35. Adding custom fields (post meta) before/during wp_insert_post()
  36. How to query posts with certain custom meta data, and output Post data
  37. post meta getting deleted on save
  38. Custom field not updating when value is empty
  39. WordPress: custom field display twice
  40. meta_compare seems to be treating values as strings instead of integers as expected
  41. How to order posts by one custom field and filter them by another one?
  42. Limit the number of acf content when displaying in post loop [closed]
  43. How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
  44. Add post meta fields, when creating a post using WordPress’ REST API
  45. Store array as single, serialized post meta field or many post meta fields?
  46. Custom Field Values not updating unless I click “Update” twice
  47. update_post_meta for repeated custom field [closed]
  48. Trying to update_post_meta function
  49. Show values of custom post meta on ‘Add new post’ page?
  50. Custom post meta field effect on the performance on the post
  51. Limits, not all post are showen when querying for posts by view count
  52. Display Custom Meta Box Field Only If Value is Present
  53. Stop sending email everytime I updates my post
  54. Best way to store everyday post views?
  55. Unable to get specific value from post meta
  56. Problem with saving large amount of data in postmeta/usermeta
  57. Custom meta is not being saved
  58. IF Custom field value equals ZERO
  59. How to use media upload on metabox post page without breaking TinyMCE?
  60. Let’s Create Custom Field Template Documentation
  61. Branch made by several custom values
  62. Access ACF fields within custom preview function?
  63. Looping inside block return
  64. WordPress creates new lines in postmeta table on post update
  65. Sort posts by clicks on download button
  66. User customising position of WordPress Featured Image
  67. Can I save post meta programatically without setting metaboxes?
  68. Insert image into sub-field with update_post_meta
  69. How to use conditional statement with custom field
  70. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  71. If metabox has content display content
  72. Best way to achieve multiple links in a post title
  73. Custom Theme Fields in Settings Menu – apply filters to one of those fields?
  74. Display Meta Data with HTML?
  75. How can I add/update post meta in a admin menu page?
  76. Get author total post votes from post meta
  77. custom filed from post in the side bar
  78. How to show ACF fields in Gridbuilder custom block
  79. How to display custom fields in hestia theme
  80. How to speed up post list slowed by update_meta_cache()?
  81. WordPress Blocks, setAttributes not saving
  82. Why isn’t update_post_meta saving?
  83. SQL query to change the value of a Custom Field
  84. Custom meta POST request fired twice when updating a post in Gutenberg
  85. Add custom field information to source meta data
  86. Update custom field on page specific to logged in user
  87. Create Meta boxes dynamically
  88. Make a custom field in admin post.php read only
  89. Delete custom meta
  90. create a custom field that let me include other posts
  91. Check if value exists before saving
  92. Get meta value when the page is a blog archive
  93. How to filter post using custom feild value in shortest and longest duration?
  94. Query Posts Via WordPress URL
  95. wp_postmeta are updated for only one page
  96. Including inline Custom Fields info with add_filter in functions.php
  97. Make Custom Fields Public in JSON – API
  98. Order by a meta field in query loop
  99. Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
  100. Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)
Categories custom-field Tags ajax, custom-field, filters, hooks, post-meta
pluggable function in theme, to be overridden by plugin
wp_commentdata: error in documentation?

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