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

SQL query to change the value of a Custom Field

If you’re looking for raw SQL query, then this should help:

UPDATE <PREFIX>postmeta SET meta_value="temp4" WHERE meta_value="temp1" AND meta_key = 'post_template'

If you want to run this query from WP, then you can use this:

global $wpdb;
$wpdb->update(
    "{$wpdb->prefix}postmeta",
    array( 'meta_value' => 'temp4' ),
    array( 'meta_key' => 'post_template', 'meta_value' => 'temp1' )
);

Related Posts:

  1. Up/Down voting system for WordPress
  2. searching by keywords in post’s metas or pagination links problem
  3. Can I exclude a post by meta key using pre_get_posts function?
  4. What is the index [0] for on post meta fields?
  5. Best way to programmatically remove a category/term from a post
  6. SQL Query to copy value of a meta_key into another meta_key
  7. Custom field metabox not showing in back-end
  8. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  9. How to hide meta box values from custom fields list?
  10. What is the advantage of the wp_options design pattern?
  11. Storing meta fields multiple times OR once with multi dimensional array?
  12. display specific custom fields
  13. Meta keywords and descriptions plugin for manually editing meta for each page/post
  14. Is it possible to store arrays in a custom field?
  15. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  16. Transients vs CRON +Custom Fields: Caching Data Per Post
  17. Unable to save datetime custom meta field using update_post_meta() function
  18. Custom Fields Bulk Edit
  19. Create custom field on post draft or publish?
  20. Display info from custom fields in all images’ HTML
  21. get_post_meta fields don’t show up on posts page
  22. Update meta values with AJAX
  23. copy attachments to another post type and change attachment url
  24. Cannot edit post meta fields with rest API
  25. Add a post meta key and value only if it does not exist on the post
  26. Order posts according to user defined order for meta values?
  27. Custom fields to save multiple values
  28. Function to change meta value in database for each post
  29. Get aggregate list of all custom fields for entire blog
  30. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  31. using multiple meta_key and meta_value in query_posts
  32. Adding custom fields (post meta) before/during wp_insert_post()
  33. MySQL Query that looks for post with Custom Field, then changes Category
  34. ACF: How to get the full field name (meta_key) by a field key?
  35. post meta getting deleted on save
  36. Custom Field Create Bulk via SQL Query
  37. filtering custom post types via meta data drop down
  38. How to add a new meta key and assign timestamp to posts
  39. Custom field not updating when value is empty
  40. meta_compare seems to be treating values as strings instead of integers as expected
  41. Limit the number of acf content when displaying in post loop [closed]
  42. Read / Watch / Listen times – meta
  43. How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
  44. How do I Implement Atomic Update of Post Metadata?
  45. How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
  46. Why is my Custom Meta Box Field Inputs NOT saving?
  47. UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
  48. Get registered custom fields or post meta even if empty
  49. Displaying multiple URLs as custom field values
  50. Show values of custom post meta on ‘Add new post’ page?
  51. Custom post meta field effect on the performance on the post
  52. get_posts in meta box dropdown not showing latest posts
  53. Limits, not all post are showen when querying for posts by view count
  54. Display Custom Meta Box Field Only If Value is Present
  55. Ordering posts by custom field named “date” in backend
  56. Stop sending email everytime I updates my post
  57. Best way to store everyday post views?
  58. Custom meta is not being saved
  59. IF Custom field value equals ZERO
  60. How to use media upload on metabox post page without breaking TinyMCE?
  61. Branch made by several custom values
  62. Looping inside block return
  63. change order of images attached to post
  64. User customising position of WordPress Featured Image
  65. how can I show name and value of Custom Fields together?
  66. Can I save post meta programatically without setting metaboxes?
  67. Insert image into sub-field with update_post_meta
  68. How to use conditional statement with custom field
  69. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  70. Gravity Forms Update post meta from template [closed]
  71. SQL: Select wordpress posts with given text string and add a custom field to them?
  72. Best way to achieve multiple links in a post title
  73. How can I add/update post meta in a admin menu page?
  74. Show array of meta_value in Edit Post Coloum
  75. Get author total post votes from post meta
  76. custom filed from post in the side bar
  77. wordpress multi user question
  78. Adding Custom Metadata to my Archive/Posts page
  79. How to improve my non-unique metadata MySQL entries?
  80. Custom Fields Not Showing (ACF not installed)
  81. Custom meta POST request fired twice when updating a post in Gutenberg
  82. Add custom field information to source meta data
  83. Update custom field on page specific to logged in user
  84. Create Meta boxes dynamically
  85. Saved Post Meta Array Returns as String
  86. Delete custom meta
  87. Problem saving meta data
  88. Check if value exists before saving
  89. Get meta value when the page is a blog archive
  90. change attachment custom field onChange event
  91. wordpress simple post multi rating with post_meta and user_meta
  92. wp_postmeta are updated for only one page
  93. query specific posts according their custom fields, using sql SELECT
  94. Custom fields / meta box output
  95. Make Custom Fields Public in JSON – API
  96. Colecting values from custom field checkboxes and displaying them in the post
  97. Build Array from Input Fields question
  98. How can i put a custom field inside this php
  99. 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)
  100. What is the best way to get a different post’s custom field/postmeta with js?
Categories custom-field Tags custom-field, post-meta, sql
filter using custom fields
Reading Content in an Array as it relates to a meta_query

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