I'm trying to Edit & Update meta_box values from front-End, Following codes are back-end. The problom is i'm fully confused with update post & update meta box.

I hardly trying to get $package value edit from front-end but not luck.

Following Code is my Back-End Page

function render_features_box($post) {
wp_nonce_field( 'zon_testimonial', 'zon_testimonial_nonce' );
$data = get_post_meta( $post->ID, '_zon_testimonial_key', true );
$package = isset($data['package']) ? $data['package'] : '';
<label class="meta-label" for="zon_package">package</label>
<input type="text" id="zon_package" name="zon_package" class="widefat" value="<?php echo esc_attr( $package ); ?>">

public function save_meta_box($post_id) {
if (! isset($_POST['zon_testimonial_nonce'])) {
return $post_id;
$nonce = $_POST['zon_testimonial_nonce'];
if (! wp_verify_nonce( $nonce, 'zon_testimonial' )) {
return $post_id;

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return $post_id;

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

        $data = array(
            'package' => sanitize_text_field( $_POST['zon_package'] )   
        update_post_meta( $post_id, '_zon_testimonial_key', $data );

In Front-End I got a form & process things but in this code post-title & post-content i can edit, but i don't understand how to get the meta_box values pass from back-end to front-end & how i can edit update with this form,

which user log in they can show their own posts and users can edit their posts in front end. look Bellow code i tried with add $package variable inside the form

Following code is portion of Front-End Page. if you need full code: pastebin

global $current_user;

if ($query->have_posts() || is_user_logged_in() || current_user_can('edit_post', $post->ID)) :
      while ($query->have_posts()) : $query->the_post();

      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 );
    <!-- edit Post Form -->

            <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>
    <input type="text" id="zon_package" name="zon_package" class="widefat" value="<?php echo esc_attr( $package ); ?>"> 
            <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' ); ?>
  • Please edit your question to describe the problem or ask the question. – Max Yudin Jul 10 '19 at 6:58
  • @MaxYudin I explained something more. – Noufal Binu Jul 10 '19 at 11:01
  • This is not the real code you work on. I'm pretty sure it will throw parse error and is invalid. public function save_meta_box() is nonsense in procedural PHP. – Max Yudin Jul 10 '19 at 11:24
  • @MaxYudin , it's a plugin I'm making OOP based plugin, I not expert in php but it this code working fine in back-end – Noufal Binu Jul 10 '19 at 11:26
  • Does not matter is it plugin or not. The code you give is unparseable, namely inexecutable. – Max Yudin Jul 10 '19 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.