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. How can I get or the intermediate size of an image with wp_get_attachment_image_src without using post meta?
  33. show hide image script after 4 seconds [closed]
  34. Restricting users to view only media library items they have uploaded?
  35. How do I disable responsive images in WP 4.4?
  36. Filter to remove image dimension attributes?
  37. How to get a list of all the possible thumbnail sizes set within a theme
  38. How to extract data from a post meta serialized array?
  39. Post meta vs separate database tables
  40. How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?
  41. Image Upload from URL
  42. Programmatically adding images to media library
  43. How do I delete all UNUSED images from my uploads directory?
  44. Set default image sizes in WordPress to hard crop
  45. Is it possible set a featured image with external image URL
  46. get attachment title based on attachment id
  47. Stop wordpress from hardcoding img width and height attributes
  48. Handle issues with change of image scaling (rounding) in 4.1 (WP Ticket #18532)
  49. Programmatically get images by URL and save in uploads folder
  50. Prevent WordPress from generating medium_large 768px size of image uploads?
  51. remove or update add_image_size
  52. Why WordPress choose data serialization over json_encode?
  53. Get Image Description
  54. How to extend the gallery block in Gutenberg?
  55. Image quality based on image size
  56. Function to get URL of original uploaded image – full size
  57. how to get original image using wp_get_attachment_image_src
  58. What is a good alternative to using $content_width for image optimization?
  59. get the attachement url for the medium sized image
  60. Can I attach image to post without adding it to post?
  61. Automatically replace original uploaded image with large image size
  62. WordPress crop tool greyed out
  63. How to scale up featured post thumbnail?
  64. Upload images to remote server
  65. Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions
  66. Each custom image size in custom upload directory?
  67. Getting Images from theme’s directory in pages
  68. Set default image link target in Gutenberg image block
  69. Add an alignment option for images
  70. How to delete resized (cropped) image uploads and prevent future resizing?
  71. How to automatically add rounded corners to thumbnails?
  72. WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
  73. Download an image from a webpage to the default uploads folder
  74. Add image size where largest possible proportional size is generated
  75. WP 4.4. responsive images browser choosing the “wrong” one
  76. After Moving a Site to Another Domain, All Images Are Lost
  77. Prevent WordPress from adding image’ title automatically
  78. Overide Gallery Default Link to Settings
  79. Retrieve featured image
  80. getting attachement images src and add classes
  81. How to change image type for specific size?
  82. Add new image size to media uploader so users can insert into post?
  83. How to insert pictures without hard coded dimensions?
  84. Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
  85. How to modify image editor dialog options on WordPress?
  86. Why WordPress automatic cropping all my images?
  87. Allow contributor role to upload images and not edit already published articles
  88. What’s the proper way to find and remove duplicate images from posts and the media library?
  89. Remove images (files) that were generated when using add_image_size()
  90. get_post_gallery with Gutenberg
  91. Is there a hook which fires after all thumbnails are generated?
  92. Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress
  93. Is there a simple way to just insert a link to an image (without inserting an image)?
  94. Watermarking Images with WordPress with WP_Image_Editor
  95. How to avoid WordPress stripping EXIF metadata when resizing images?
  96. is it possible to replace the use of gd_lib with imagick or ImageMagick?
  97. How to have different captions for same image, for galleries?
  98. Get attachment/image info in JS
  99. How to reference a theme image in a stylesheet?
  100. wp_get_attachment_image_src and server path
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
  • 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