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

Remove “%” from strings in serialized arrays in wp_postmeta

General idea would be to loop through all attachments to retrieve, modify and write back their meta.

Something like this (test thoroughly before using on anything important):

$posts = get_posts(array(
    'post_type' => 'attachment',
    'numberposts' => -1,
));

foreach( $posts as $post ) {

    // retrieve data, unserialized automatically
    $meta = get_post_meta($post->ID,'_wp_attachment_metadata', true);

    // do stuff with $meta array

    // write it back
    update_post_meta($post->ID, '_wp_attachment_metadata', $meta);
}

Related Posts:

  1. How to delete outdated, wrongly sized images in _wp_attachment_metadata?
  2. How can I store an image in the database with Transients API?
  3. Regenerate missing _wp_attachment_metadata
  4. Is there a shortcut to change bulk BMP images to JPG images in a site?
  5. WP 3.4 has missing photo data
  6. Update image links in database
  7. Retrieving an alt tag from a custom field
  8. Get thumbnail url of custom meta image?
  9. Image thumbnails not available post migration, but still accessible via direct URL – DB issue
  10. Image upload appearing as broken images following server move
  11. Dynamic tagged image galleries
  12. I got an issue after i migrated a site
  13. Generate images to be associated for tag and category?
  14. Display an icon with get_post_meta?
  15. Upload media only to DB
  16. insert image alongwith with custom data via a frontend form
  17. Images are not showing after moving WordPress installation from server to localhost?
  18. Images not found after migrating WordPress website
  19. Image not showing using a custom function and get_post_meta
  20. Can I achieve this with WordPress?
  21. How to join Caption AND Description Meta Fields as one combined-caption in Image Block
  22. Save media files (images) to database instead of the filesystem
  23. How to Display Image Caption but Not Alt Text
  24. A query to substitute images paths in gutenberg (website migration)?
  25. JPG Image extension not inserting into Custom table of wp
  26. How to delete images from database with product
  27. get_post_meta returning broken path in image src
  28. Images not showing after moving site
  29. Adding Image Description below Images Inserted into Posts
  30. Why images are disappearing on WordPress web site?
  31. get_post_custom: get image URL instead of image ID
  32. Set default image sizes in WordPress to hard crop
  33. Is there a way to define a default caption to all uploaded images
  34. How can I add the “Use as featured image” to a custom metabox?
  35. How to place an image into header.php? [closed]
  36. Uploading an image as featured image from frontend form
  37. Delete all post meta except featured image
  38. How to upload images from my directory into my wordpress?
  39. Add a featured image in my theme?
  40. @wordpress/create-block image url in css
  41. How does WordPress work out the srcsets?
  42. help getting featured image using get_posts
  43. Why can I not view image attachment pages?
  44. Restrict Image Uploads to a Certain File Type
  45. Multiple postmeta with same name for one post in wp_postmeta table
  46. Image popup in a lightbox / overlay from the backend 3.5 admin area (plugin)
  47. media sideload image and Google Content
  48. How to display alt tags in img src?
  49. Big Image on Featured Post, Normal on Single Post
  50. Making images in posts link to the image file rather than the attachment page
  51. offload media to external services [closed]
  52. How to create ‘Local’ filters for WordPress srcset sizes in template parts?
  53. Jetpack’s photon causes local site to try and serve images from WordPress CDN [closed]
  54. How to stop wordpress always displaying full-res images
  55. Transfer only original images to new site
  56. How to filter the image embed code based on link type
  57. Update post meta does not serialize array
  58. Retrieve image from content, assign it as a featured, and then remove it from the content
  59. Custom Loop, Match Category with Page: How to display post featured image?
  60. Include an image within auto the_excerpt?
  61. Redirect to another page using contact form 7? [closed]
  62. Google verification challenge with file location
  63. Images are not showing up in “Uploaded to this post”
  64. A little confused as to what add image size actually does
  65. Get thumbnail URL :)
  66. Right click&copy images: protection
  67. Cache DB queries result
  68. change order of images attached to post
  69. Changing Image Size Settings does not show in Image Details
  70. Get the URL, width and height of an image where the width and height are a specified minimum
  71. Metabox image upload value
  72. image_downsize returning an Array?
  73. How to disable a WP Image Block to link to itself?
  74. How can I update this array built from post meta data?
  75. Is there a layout to place 2 same sized images in two columns on the WordPress page?
  76. How to change an image source when rendering on frontend?
  77. How can I change the header on the pages?
  78. Optimise wordpress database using SQL after deleting registered images from Media Folder
  79. WordPress on IIS works except for image upload widget: Win 10 Pro
  80. ADD class to all my images (thumbail)
  81. How to show a full page when someone links directly to an image on my site
  82. blank page with wp_get_attachment
  83. Can i use my Old Post image URL in my new post?
  84. Responsive Featured Images Not Working
  85. How can we achieve this image css style?
  86. WordPress 404 Images – Images not found after deleted from media
  87. How to Make Only Images Connected to a Post Show? Not Entire Media Collection?
  88. Bypass wp_safe_remote_get()?
  89. Redirect Causes Missing Images
  90. Specify which image sizes are created on a per image basis
  91. Rename uploads filenames to POST-ID on upload
  92. How do I retrieve a value from a multi – dimensional array using get_post_meta? [duplicate]
  93. How to include featured image on blog post preview?
  94. Hover images and Videos
  95. My subdirectory sites images (except webP) are throwing to 404 page even they are exist
  96. Multisite image URLs incorrect in editor
  97. Get field added via attachment_fields_to_edit filter in Gutenberg
  98. Fix position of an image while using elementor pro gallary widget
  99. Neither intermediate_image_sizes_advanced or intermediate_image_sizes filter is firing
  100. How to allow shortcodes in image descriptions?
Categories images Tags array, database, images, post-meta
Allow front end users to add data to a custom post type
Review site using WordPress

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