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. Hide individual page title using checkbox in custom meta box?
  23. Add “upload media” button in meta box field
  24. Execute action after post is saved with all related post_meta records (data)
  25. How get post id from meta value
  26. get_post_meta returning empty string when data shows in the database
  27. publish_post action hook doesn’t give post_meta_data
  28. How to access the post meta of a post that has just been published?
  29. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  30. Query between two meta values?
  31. get_post_meta doesn’t work
  32. loop through all meta keys with get_post_meta
  33. How to add multiple featured image in meta box in post editor?
  34. Change the post date from a meta box
  35. Saving html into postmeta without stripping tags – safe?
  36. How to show Published date and/or Modified date
  37. update_post_meta and get_post_meta not working
  38. wp_update_user isn’t instantly?
  39. How to use update_post_meta inside wp_trash_post
  40. “update_post_meta” not working in “wp_insert_post_data” hook
  41. Set default post author to none on new post
  42. Display All Custom Post Fields and Values, Unless Empty
  43. Posting to a Custom Post Type from front end – user generated content
  44. How to create a meta_query to get all posts with a specific meta data?
  45. Why is my Custom Meta Box Field Inputs NOT saving?
  46. hide posts with specific meta data from admin page
  47. Post MetaTable Overload
  48. Custom RSS Feeds & Post Meta Data
  49. New WP_Query loop in admin causes problems
  50. Get a row from a separate table by matching a posts meta_key to a tables ID column
  51. get_post_meta is showing file url in url bar
  52. How to check if a post meta key/value pair already exists for a specific post
  53. Reset/delete post views meta/custom field after X hours or minutes or seconds
  54. Date format – Meta Box plugin
  55. Have lots of meta for posts, is it better to get at all at once or each individually
  56. How to use media upload on metabox post page without breaking TinyMCE?
  57. Let’s Create Custom Field Template Documentation
  58. Update post meta dynamically
  59. Is it safe to add a new field to meta_value field?
  60. Need a SQL query to update meta_key=’_price’ with value in meta_key=’_regular_price’
  61. Display current user’s custom post meta in sidebar
  62. add_post_meta doesn’t work
  63. Can I save post meta programatically without setting metaboxes?
  64. How to get single value from get_post_meta() array of values?
  65. Editor meta box Showing but not saving
  66. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  67. wordpress update multiple posts post meta
  68. get_template_part() isn’t loading author information
  69. get Insert id for meta field
  70. Add post’s category as a meta tag to the post
  71. How can I query for posts using a date stored in post-meta?
  72. Is duplicate `_wp_attachment_image_alt` meta key allowed?
  73. Select another post in a post meta like a parent page is selected while editing a page
  74. How can i set media attachments to the author of the post or page for already existed posts with attachments
  75. How to get posts by meta value as multi-dimensional array?
  76. How to modify default meta link format
  77. Something adding an excessive meta description
  78. update_post_meta doesn’t work
  79. how to query posts using value in meta post array
  80. delete post meta data in array WordPress
  81. Custom Meta Fields that are Echo’d are removed on post update?
  82. Save, update, get and sanitize post meta as HTML not plain
  83. How to add dynamic content in title and meta description in wordpress theme for homepage, post page, category, tag and pages
  84. How to call get_post()?
  85. WordPress AJAX load post metadata in modal
  86. add_post_meta only adding 1 character
  87. Edit is changing my custom’s post type parent id
  88. Edit post meta direct from post.php?
  89. Looking for suggestions on creating simple database (Help!!)
  90. Can’t save drop down select date in meta boxes
  91. How do I delete element from a serialized array upon deletion of a post?
  92. Get meta information from post parent
  93. Function is Missing an Action Hook
  94. Counting number of identical meta keys
  95. Use a Variable in update_post_meta as the $meta_key
  96. query with custom field
  97. Using Form to alter PHP variable [closed]
  98. Chance post id into post name
  99. CPT posts in drop downed in meta box on page doesn’t return post ID
  100. Saving multiple custom meta box fields
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
  • 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