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

Auto save title as custom meta field value

Well because your code seems like to be bugy/not full – i wrote my code. This will add one meta box with one text field in post (you can change it to be added in your custom post_type)- Post title. Also i had to use QUERY to update/add title, because i can not find any other way, $post->post_title="some title" do not work.

If you happy with this code – please mark as good answer, good luck 🙂

EDIT:

 // Save post with your title
function save_the_title($post_id) {
global $wpdb;


if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  return;

if ( !current_user_can( 'edit_post', $post_id ))
    return $post_id;

 $newtitle="";  // SET YOUR TITLE HERE 
 $old_title = get_post_meta($post_id, '_title', true);
 if($newtitle != '' && $newtitle != $old_title) {
 update_post_meta($post_id, '_title', $newtitle);
 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_title = %s WHERE ID = %d ",$title1,$post_id) );

} 

 }

 add_action('save_post', 'save_the_title'); // save the custom fields

Related Posts:

  1. post_title in save_post action
  2. Execute action after post is saved with all related post_meta records (data)
  3. Add post meta based on another post meta value before publish post
  4. Get updated post meta on save_post action?
  5. Correct processing of `$_POST`, following WordPress Coding Standards
  6. Delete post meta conditionally after save post
  7. Set default Custom Post Meta Value
  8. Editing does not change post_name
  9. Save post meta foreach loop
  10. troubles with get_post_meta (and saving it)
  11. wp_insert_post inside save_post adds wrong metadata to inserted post
  12. Save frontend submission form field as custom field
  13. get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
  14. if condition from post_meta not working in save_post
  15. Hide individual page title using checkbox in custom meta box?
  16. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  17. Adding meta tag without plugin
  18. Meta compare with date (stored as string) not working
  19. How to update/insert custom field(post meta) data with wordpress REST API?
  20. Remove WordPress.org Meta link
  21. Front-end update_post_meta snippet displays white screen?
  22. How to get meta value in wp_attachment_metadata
  23. update_post_meta() not working in save_post
  24. Clean up output added via wp_head()
  25. Get post from meta_key and meta_value
  26. get_post_meta returns bool(false)
  27. How to get custom post type to display post meta on archive pages?
  28. Mass importing json data into custom fields (postmeta)
  29. How to echo get_post_meta (Fluent-Framework)
  30. WP_POSTMETA changes site crash
  31. meta_post_meta return value 1
  32. How to use post_id with a Class?
  33. INSERT ON DUPLICATE KEY UPDATE failes in postmeta table
  34. Set Checkbox as checked by default
  35. WordPress front-end media (image) upload ERROR!
  36. replacing the_autor or make callback
  37. Some post meta fields stop saving after a few successful saves
  38. Set default value field meta_Value [closed]
  39. Can’t access post meta on new post creation (cpt)
  40. Save an array of values in the post meta box
  41. get_post_meta() empty in preview WHEN custom post is published [closed]
  42. Add Embed.ly API objects to post_meta on update
  43. Is it possible to retrieve a post and its metadata at the same time?
  44. cleaning up safely wordpress wp_postmeta table
  45. Post meta as array looks like string instead of array
  46. Why does get_transient() always return string even if integer set?
  47. Author_meta ONLY if it exists
  48. How to test the outcome of a wpdb query?
  49. Change post author without using wp_update_post()
  50. How do I manage custom meta in post revisions in the Block Editor era?
  51. Generate metadata for cloud images
  52. Is there a way to disable post meta caching for development?
  53. How to extract data from a post meta
  54. Get post_meta from specific post [closed]
  55. update_post_meta not working?
  56. Change wordpress meta tag description using WP functions
  57. Check for page template on save_post hook
  58. getting the post_id from the post_meta
  59. Cant create or update meta fields using WordPress REST API
  60. Filter posts by meta key
  61. Display current ranking of post as a number in post title
  62. delete duplicates wp_postmeta
  63. Post Thumbnail missing when using webp format while sharing
  64. Bulk Update Post Meta Values from Different Post via Rest Api
  65. update_post_meta() is not saving the value
  66. Only show meta on one post type on search results page
  67. How to register post meta with multi level arrays?
  68. If I disable screen options, does WP still try to update post meta?
  69. Can we have duplicate key pair values in post meta data?
  70. I created a Custom Meta Box but it is not displaying the value on my post page
  71. Meta data being pulled from wp-login.php
  72. Is it possible to pass an whole array using custom field in wordpress?
  73. Get post content before rendering
  74. Rename image filename using ‘media_handle_upload’
  75. Update Post metafield of specific categories
  76. Custom post type meta fields missing on save_post_type
  77. Using Self Hosted Video URL With Custom Fields
  78. Multiple postmeta values to the same post_id/meta_key combination?
  79. get_post_meta not work in php foreach
  80. Why are my custom metaboxes not updating the post meta?
  81. Problem serializing single quote and double quote into post meta
  82. Storing post_meta fields in array
  83. Performace on 1 million plus meta fields vs 1 field with 1 million multi array
  84. Fetching array of postmeta with $wpdb and in_array conditional
  85. Piklist File Upload
  86. wp_schedule_event not working
  87. how to echo/display the custom field value in specific custom field name?
  88. update_post_meta() not working in bulk option
  89. How to update the ‘modified_time’ of a post ONLY when content is changed?
  90. Multiple If else statements on Search Result Page
  91. WordPress join posts with meta values of array type
  92. Export posts with postmeta without ID?
  93. get_children filter with postmeta
  94. How can I display my meta value in a textarea? [closed]
  95. Post meta box data not saving
  96. Update post meta array – add new, single value
  97. Cannot read properties of undefined (reading ‘useEntityProp’)
  98. How to update post view count?
  99. Search posts by meta key in admin and front
  100. sanitize meta input
Categories post-meta Tags post-meta, save-post, title
NextGEN Gallery styles don’t work [closed]
Site layout problems when logged in due to admin bar

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