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. SQL query based on two different custom field values
  4. Can I exclude a post by meta key using pre_get_posts function?
  5. Custom post meta field effect on the performance on the post
  6. How to get custom post meta using REST API
  7. Difference between meta keys with _ and without _ [duplicate]
  8. Orderby meta_value only returns posts that have existing meta_key
  9. What is the index [0] for on post meta fields?
  10. What is “meta_input” parameter in wp_insert_post() used for?
  11. How to enable revisions for post meta data?
  12. The “_encloseme” Meta-Key Conundrum
  13. Best way to programmatically remove a category/term from a post
  14. SQL Query to copy value of a meta_key into another meta_key
  15. How to correctly call custom field dates into a posts_where filter using SQL statements
  16. Using get_post_meta with new_to_publish
  17. Add custom fields to search
  18. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  19. How to rename a custom field?
  20. Custom field metabox not showing in back-end
  21. So much data in postmeta
  22. Can I count the number of users matching a value in a multiple value key?
  23. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  24. How to hide meta box values from custom fields list?
  25. Auto sort the wp-admin post list by a meta key
  26. get_post_meta() unserialize issue – returns boolean(false)
  27. What is the advantage of the wp_options design pattern?
  28. Storing meta fields multiple times OR once with multi dimensional array?
  29. Allow user to create instances of custom field
  30. display specific custom fields
  31. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  32. Meta keywords and descriptions plugin for manually editing meta for each page/post
  33. How to display multiple Post meta_key/meta_values by SQL query
  34. passing argument to get_template_part() or a better way to code
  35. Is it possible to store arrays in a custom field?
  36. Get updated meta data after save_post hook
  37. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  38. Save HTML formatted data to post meta using add_post_meta()
  39. importing data from non-wordpress mysql db
  40. Bulk move (or copy) from a custom field to the post content?
  41. Create meta boxes that don’t show in custom fields
  42. Transients vs CRON +Custom Fields: Caching Data Per Post
  43. Unable to save datetime custom meta field using update_post_meta() function
  44. post meta data clearing on autosave
  45. Custom Fields Bulk Edit
  46. Create custom field on post draft or publish?
  47. Display info from custom fields in all images’ HTML
  48. Ordering posts by anniversary using only day and month
  49. get_post_meta fields don’t show up on posts page
  50. Update meta values with AJAX
  51. How to break meta values into different items and avoid duplicates?
  52. copy attachments to another post type and change attachment url
  53. Cannot edit post meta fields with rest API
  54. ajax delete value from custom field array
  55. Save attachment custom fields on front end
  56. How to use pagination with get_post_meta
  57. Copying Custom Meta Values from existing post to a duplicate post
  58. Add a post meta key and value only if it does not exist on the post
  59. Move value of one custom field to another
  60. Order posts according to user defined order for meta values?
  61. Displaying posts with only upcoming dates according their custom field date value
  62. Custom fields to save multiple values
  63. Custom fields: In what order are they saved into the DB?
  64. Function to change meta value in database for each post
  65. Get a post_id where meta_value equals something in a serialized meta_value field
  66. Get aggregate list of all custom fields for entire blog
  67. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  68. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  69. Custom field value based on other custom field values
  70. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  71. How to save a ToggleControl value in a meta field?
  72. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  73. Saving custom image meta fields
  74. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  75. How to display Meta Field Value?
  76. MySQL query to set wp_postmeta using term_taxonomy_id value
  77. How to Validate Post Meta type/extension (Video File Image File etc)
  78. Get all meta keys assigned to a post type
  79. using multiple meta_key and meta_value in query_posts
  80. Custom Meta Box not Saving in Posts with Gutenberg Editor
  81. Get all posts that do not have a specific custom field without using a subquery
  82. Adding custom fields (post meta) before/during wp_insert_post()
  83. Combine multiple custom field values into single value
  84. How can I sort homepage by a meta value?
  85. Get specific custom field keys from a post and put into an array
  86. How do I use wp_query for WordPress search?
  87. Nav Menu – Add class based on meta keys
  88. How to query posts with certain custom meta data, and output Post data
  89. MySQL Query that looks for post with Custom Field, then changes Category
  90. Order query by meta_value with multiple custom fields
  91. ACF: How to get the full field name (meta_key) by a field key?
  92. How to wrap meta values seperated by comma in ? [closed]
  93. Bulk remove post meta
  94. post meta getting deleted on save
  95. How to create html block to display extra information on woocommerce single product page
  96. Can’t get post ID using wp_insert_post_data
  97. Custom Field Create Bulk via SQL Query
  98. Unique Post Meta Values
  99. Create Multiple File Upload Metabox in WordPress
  100. filtering custom post types via meta data drop down
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
  • 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