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

Update an existing post in a custom post type

Solved.. I did it in 2 steps and it works perfectly!

if(isset ($_POST['new_title']) && $_POST['new_title'] != "")
                            {

                                $post_type = get_post_type( get_the_ID() );
                                $id_post = get_the_ID();                
                                $title = get_field('titre');

                                $postInfo = array(
                                    'post_type' => $post_type,
                                    'ID' => $id_post
                                );

                                $id = wp_update_post($postInfo);

                                update_post_meta( $id, 'titre', $_POST['new_title'] );

                                $new_title = $_POST['new_title'];

                                $new_elem = array(
                                    'post_type' => $post_type,
                                    'ID' => $id_post,
                                    'post_title' => $new_title
                                );

                                wp_update_post($new_elem);

                            }

Related Posts:

  1. what is the correct way to compare dates in a WP query_posts meta_query
  2. Get post with multiple meta keys and value
  3. Echo all meta keys of a custom-post TYPE
  4. Post metadata deletes itself
  5. Custom Post Type: Set post_title equal to a custom post type field
  6. I can’t set meta_key in my custom post type query
  7. How can I include meta box content when searching?
  8. update a post meta from a single table cell TablePress
  9. Automatically adding meta data to posts or multiple query help
  10. Trigger “unsaved changes” dialog for custom post meta changes
  11. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  12. Displaying custom posts only if custom meta box’s date is not expired
  13. Displaying Metabox value (custom post type taxonomy)
  14. How do I sort a custom post type admin column using two meta keys?
  15. How can I display my custom metaboxes on a custom post template?
  16. Custom Post Type, Saving Multiple Checkboxes
  17. Create a random unique 6 digit number as custom field for custom post type
  18. Export entries and multiple custom field meta to .csv?
  19. how to interconnect custom post types?
  20. orderby in custom WP Query does not work
  21. Insert post metadata for all posts in CPT at once if metadata no existent
  22. Display custom post type from dynamic custom field
  23. Populate dropdown from one custom post type inside another custom post type
  24. Notice: Undefined index: error and understanding wordpress
  25. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  26. Deleting Custom Posts & Meta Data on Uninstall
  27. How do I create an archive page as a including metadata?
  28. Two Custom Post Types Many to Many Relationship
  29. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  30. post meta parameter in post custom-post-type endpoint with restapi
  31. Update postmeta Parent when post_status child change
  32. Update database from Quick Edit according to Checkbox state of Custom Post Type
  33. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  34. Dynamic Custom Fields
  35. Show Custom Post Type meta boxes only on Page Edit
  36. Custom filter function not working with Custom post type
  37. Getting thumbnails of a custom posts featured images in a page-templates metabox
  38. Custom fields for custom post type
  39. Show future events based on custom field AND order by date
  40. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  41. create custom meta box with default value
  42. How to Echo Metadata Value in Currency Format
  43. Issue on Working with Metabox – Checkbox to enable Sale Items
  44. delete_post_meta() for whole CPT / multiple posts?
  45. How to move a post to different post type with all meta data?
  46. Why do I have to press the “Update” button twice to save my meta box values?
  47. how to show records that don’t have custom meta value
  48. WP API Response does not show my registered metadata
  49. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  50. get_post_meta returns NULL in front-end, but correct result in back-end
  51. Problem with adding custom post type meta to header by plugin
  52. Meta box data is saved but NOT displayed in the meta box text field. Why?
  53. How to call a post’s metadata in shortcode.php?
  54. Echo custom post meta from options array
  55. Value of post meta dropdown is not showing in WordPress
  56. WP_Meta_Query object with conditionals
  57. Trying to write shortcode with get_post_meta but isn’t working
  58. HM CMB: Post Select Field for CPT ID
  59. updating one custom meta field only
  60. Add a class to post_class if more than one post shares same meta_value_num
  61. Function to return values from metabox
  62. Problem Saving Custom Post Type Meta Values
  63. Custom fields for post or terms which don’t update on post update
  64. Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
  65. Add a form in every post and save data in post meta
  66. How can I add a meta[] to my custom post type and search by term with the Rest API?
  67. Show posts from WP Custom Post Type selected from a field in a metabox
  68. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  69. Peepso: Add extra data field (custom post meta) to postbox
  70. Change picture attachment meta of all occurrences of a picture
  71. Unknown Post Meta Records
  72. Get Previous Post based on Custom Field Name, for Custom Post Type
  73. Saving custom post types post_meta over REST-API fails
  74. add action save post type and update post meta woocommerce
  75. How to Disable option of meta field if that option is selected for any other post in custom post type?
  76. get_post_meta not working with variable as a post_id for dynamically get the postid
  77. Linking posts together with Advanced Custom Fields “both ways”
  78. Add more custom fields when creating a new custom post type
  79. Stripe multiple transactions
  80. How to get Current week and current date record wp query
  81. Edit is changing my custom’s post type parent id
  82. Disable Facebook Comments Automatically On CPT
  83. Problem with ‘save_post’ hook not running
  84. WordPress custom post type
  85. Edit post meta direct from post.php?
  86. Howto: use existing post_meta as options for a different metabox (checkboxes or list)
  87. Custom Post Type meta oembed html output resulting in WSoD
  88. Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
  89. Change the contents of a dropdown through the admin panel?
  90. Top 30 Songs using Custom Post Type
  91. Advice Needed for Post Meta Database Efficiency
  92. fetch meta fields inside a widget
  93. Custom post type – update_meta not working
  94. Use a Variable in update_post_meta as the $meta_key
  95. Changing to different post type maintains the redirection?
  96. Post Meta for Custom Post Types
  97. How do I add the “orange counter” next to a Custom Post Type?
  98. getEntityRecords/useEntityRecords: How to use CPT metadata?
  99. CPT meta values intermittently return empty
  100. Quering a post object based on another related post object
Categories custom-post-types Tags custom-post-types, post-meta
Is the only way to add taxonomy terms via an admin panel?
Cannot Create a new Post [closed]

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