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

add post meta front end edit

This code should be conditional first and then form output since you can’t use wp_redirect after headers are set and you are updating so use update_post_meta instead of add_post_meta.

Try:

    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "edit_post" && isset($_POST['pid'])) {
    $the_post = get_post($_POST['pid']); 


    $the_post = array(); 
    $the_post['post_content'] = $_POST['description'];
    $the_post['data'] = array($_POST['data']);

    $pid = wp_update_post($the_post); 
    update_post_meta($pid, 'rating', $the_post['data'], true);

    $link = get_permalink( $pid );
    wp_redirect($link);
}

<!-- edit Post Form -->
    <div id="postbox">
        <form id="edit_post" name="edit_post" method="post" action="">
        <p><label for="description">Description</label><br />
            <textarea id="description" name="description" ><?php echo $post_to_edit->post_content; ?></textarea>
        </p>
        <!-- wine Rating -->
        <fieldset class="data">
                  <label for="data">data</label>
                  <input type="text" value="" id="data" size="60" tabindex="20" name="data"><?php echo (!empty($val = get_post_meta($post_to_edit->ID,'rating',true))) ? $val : ''; ?></textarea>
        </fieldset>

        <p align="right"><input type="submit" value="Edit" tabindex="6" id="submit" name="submit" /></p>
        <input type="hidden" name="action" value="edit_post" />
        <input type="hidden" name="pid" value="<?php echo $post_to_edit->ID; ?>" />
        <?php wp_nonce_field( 'edit-post' ); ?>
        </form>
    </div>

Related Posts:

  1. post formats – how to switch meta boxes when changing format?
  2. Adding an assisting editor box to Post page
  3. Consolidate Metaboxes into 1 Big Metabox
  4. Metabox Data not being saved [closed]
  5. Options to get my custom post type metadata via the WordPress API
  6. Update post meta in woocommerce order frontend
  7. Editing does not change post_name
  8. Mass removing CSS from 1,700 post [closed]
  9. Add box with custom per-page properties
  10. I can not display meta value in extras.php and template-tags.php
  11. After updating the custom post type, metafields disappear from the post.php edit menu, how do I fix it?
  12. Add post meta data date to event
  13. Check if any meta on the post has value then display content
  14. If I disable screen options, does WP still try to update post meta?
  15. Get or set values in post meta
  16. I created a Custom Meta Box but it is not displaying the value on my post page
  17. update_post_meta() throws Uncaught error: Cannot create duplicate attribute
  18. add_post_meta not saved
  19. Remove action of an external plugin after checking if custom post meta is set
  20. How we insert values into database using metabox WordPress?
  21. Post meta box data not saving
  22. Filtering Tabs in a Custom Post Type’s Edit Page
  23. Hide individual page title using checkbox in custom meta box?
  24. How do I retrieve the slug of the current page?
  25. Most efficient way to get posts with postmeta
  26. Get posts by meta value
  27. How can I put a custom meta box above the editor but below the title section on the edit post page?
  28. Explanation of update_post_(meta/term)_cache
  29. How to extract data from a post meta serialized array?
  30. Passing error/warning messages from a meta box to “admin_notices”
  31. Add “upload media” button in meta box field
  32. How to save an array with one metakey in postmeta?
  33. WordPress is stripping escape backslashes from JSON strings in post_meta
  34. How can I get the post ID from a WP_Query loop?
  35. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  36. What is the index [0] for on post meta fields?
  37. How to update_post_meta value as array
  38. Adding meta tag without plugin
  39. What’s the point of get_post_meta’s $single param?
  40. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  41. How to edit a post meta data in a Gutenberg Block?
  42. Sanitizing integer input for update_post_meta
  43. Execute action after post is saved with all related post_meta records (data)
  44. Lack of composite indexes for meta tables
  45. How can I retrieve multiple get_post_meta values efficiently?
  46. How do I position meta_box on post edit screen after the title?
  47. Get a single post by a unique meta value
  48. if get_post_meta is empty do something
  49. How we get_post_meta without post id
  50. How get post id from meta value
  51. What is the code to get the download link for a product in WooCommerce?
  52. Safe to delete blank postmeta?
  53. Custom field metabox not showing in back-end
  54. advanced custom fields update_field for field type: Taxonomy
  55. update_post_meta not saving when value is zero
  56. Add custom fields within meta box class “on the fly”
  57. Content hooks vs User hooks
  58. Meta compare with date (stored as string) not working
  59. How to hide meta box values from custom fields list?
  60. How to group meta boxes on the post edit page
  61. Trying to get custom post meta through Jetpack JSON API [closed]
  62. How to update/insert custom field(post meta) data with wordpress REST API?
  63. get registered metaboxes by post type or post ID
  64. How do I remove all the metaboxes for a custom post type?
  65. Restrict post edit/delete based on user ID and custom field
  66. get_post_meta returning empty string when data shows in the database
  67. publish_post action hook doesn’t give post_meta_data
  68. Remove WordPress.org Meta link
  69. Remove post meta keys
  70. How to access the post meta of a post that has just been published?
  71. Why time functions show invalid time zone when using ‘c’ time format?
  72. How to get meta box data to display on a page
  73. Save metabox with multiple checkbox array
  74. esc before saving or before displaying does it matter?
  75. Why is get_post_meta returning an array when I specify it as single?
  76. How to batch update post content with custom post meta value
  77. How to update/delete array in post meta value?
  78. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  79. Add a meta description to home page?
  80. Get all posts from custom post type and insert in select input as metabox
  81. How to Make a Categories Meta Box with Hierarchical Checkboxes on Frontend?
  82. Meta Boxes in Front End Post Submission Form
  83. Add search to list of categories in post editor
  84. Detect meta value changes when post is updated (post_updated)
  85. delete unused postmeta
  86. Should I sanitize custom post meta if it is going to be escaped later?
  87. Add post meta based on another post meta value before publish post
  88. How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
  89. Check if meta key value already exists
  90. Front-end update_post_meta snippet displays white screen?
  91. Query between two meta values?
  92. Save both current and new version of post meta
  93. Get Advanced Custom Fields values before saving [closed]
  94. Give extra post-meta to RSS feeds
  95. How to get meta value in wp_attachment_metadata
  96. WP REST API “rest_no_route” when trying to update meta
  97. Clean up output added via wp_head()
  98. List posts under meta_value heading
  99. Create meta boxes that don’t show in custom fields
  100. Why am I getting an infinite loop with have_posts?
Categories post-meta Tags front-end, metabox, post-editor, post-meta
How to approach displaying products with no shopping cart plugin or post type?
How to change a meta value (of a published post) after X days.?

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