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. Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
  12. Can I exclude a post by meta key using pre_get_posts function?
  13. Is there a way to set default custom fields when creating a post?
  14. Custom post meta field effect on the performance on the post
  15. How to get custom post meta using REST API
  16. Difference between meta keys with _ and without _ [duplicate]
  17. Orderby meta_value only returns posts that have existing meta_key
  18. What is the index [0] for on post meta fields?
  19. What is “meta_input” parameter in wp_insert_post() used for?
  20. How to enable revisions for post meta data?
  21. The “_encloseme” Meta-Key Conundrum
  22. Add subtitle to Woocommerce product title
  23. Best way to programmatically remove a category/term from a post
  24. Filter WP_Query for posts having a certain meta-value
  25. Using get_post_meta with new_to_publish
  26. Apply the_content filter to a custom field with multiple values
  27. Custom field metabox not showing in back-end
  28. So much data in postmeta
  29. Can I count the number of users matching a value in a multiple value key?
  30. Pass all custom fields through the same filter on post load?
  31. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  32. How to hide meta box values from custom fields list?
  33. Auto sort the wp-admin post list by a meta key
  34. get_post_meta() unserialize issue – returns boolean(false)
  35. What is the advantage of the wp_options design pattern?
  36. Storing meta fields multiple times OR once with multi dimensional array?
  37. Allow user to create instances of custom field
  38. display specific custom fields
  39. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  40. Edit Custom Database Tables in WordPress
  41. Fetch and show multiple custom fields via AJAX
  42. Filter results with custom field values and dropdown
  43. Meta keywords and descriptions plugin for manually editing meta for each page/post
  44. getEntityRecord without knowing the post type
  45. passing argument to get_template_part() or a better way to code
  46. Is it possible to store arrays in a custom field?
  47. Archive sorting functions by custom fields (front-end)
  48. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  49. Save HTML formatted data to post meta using add_post_meta()
  50. importing data from non-wordpress mysql db
  51. Check before publishing, if already exist post with current custom field value
  52. Query postmeta values, and return multiple post_titles for common meta value
  53. When post is updated, custom metadata in text area field is overwritten
  54. Get custom fields when hover link of post
  55. Filter and display a specific custom field value [closed]
  56. Adding custom fields to images
  57. How to save dynamically generated value in post type?
  58. Hide H1 Title using the_title filter
  59. wordpress simple post multi rating with post_meta and user_meta
  60. Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
  61. How to filter post using custom feild value in shortest and longest duration?
  62. Query Posts Via WordPress URL
  63. wp_postmeta are updated for only one page
  64. update_post_meta not working in action hook
  65. how to show this part only in the single post page?
  66. Custom Field: Display only if a specific key is selected outside the loop
  67. Change event firing in wordpress
  68. Display meta data from a custom field within plugin Category Grid View Gallery
  69. Incorrect data after modifying post using backlink from wp_die
  70. When editing a post with a custom meta box the values aren’t displaying correctly
  71. Hard Define Custom Field Value
  72. Add custom fields after post/page title
  73. Create widget that filters posts on current page based on entered value
  74. Custom fields / meta box output
  75. Including inline Custom Fields info with add_filter in functions.php
  76. If post custom meta data is not set, show normal state
  77. Sort posts after filtering them through multiple taxonomies
  78. add_post_meta insert null value into Database
  79. Make Custom Fields Public in JSON – API
  80. How do i output images from URL’s added to the same custom field key
  81. Retrieving custom field as shortcode
  82. Colecting values from custom field checkboxes and displaying them in the post
  83. Build Array from Input Fields question
  84. How to automatically create a custom field when a post is published?
  85. custom field with links
  86. add multiple values (array) to post meta_input
  87. Order by a meta field in query loop
  88. Order shipped by which driver[hook for woocoomerce order staus changed and popup in admin panel ] [closed]
  89. How can i put a custom field inside this php
  90. Add custom fields to specific menus
  91. 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)
  92. save all acf options in one meta_value [closed]
  93. How to add new Metadata options (Date, Author, etc.) for Posts?
  94. WP Query Args – search by meta_key or title
  95. Saving multiple custom meta box fields
  96. Search for meta_query does not return any result if combined with title
  97. get Custom field label (select/dropdown) on front end
  98. SQL query based on two different custom field values
  99. Block Editor – Meta values not saved, meta changes to empty array on update
  100. What is the best way to get a different post’s custom field/postmeta with js?
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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