How to use plugin add_meta_box similar using in wp-admin

I am creating a form in front same as using in wp-admin.

there is meta boxes using .

Read More

I want to konw how I can use that meta box in front page.

right now I am using

do_action( 'do_meta_boxes', $post_type, 'normal', $post );

but it’s not working as $wp_meta_boxes; is null in front end.

How I call the boxes in front end.

Thanks in advance.

Related posts

1 comment

  1. I think meta boxes are meant for the administrative interface only and the corresponding actions are only fired in the dashboard.
    Instead I suggest you use a normal form, like in the example below (use this code in you page template). Note that you must sanitize the data comming from the form before saving it to the database!

    <?php
    
    // submit the form
    if(isset($_POST['submit_form'])){
    
    // IMPORTANT: SANITIZE AND VALIDATE THE POST VALUES HERE
    
    // update the post meta
    update_post_meta(get_the_ID(), 'firstname', $_POST['firstname']);
    update_post_meta(get_the_ID(), 'lastname', $_POST['lastname']);
    
    }
    
    ?>
    
    <?php
    // get the post meta
    $firstname = get_post_meta(get_the_ID(), 'firstname', true);
    $lastname = get_post_meta(get_the_ID(), 'lastname', true);
    ?>
    
    <form action="#" method="post">
        First name:<br>
        <input type="text" name="firstname" value="<?php echo esc_attr($firstname);?>">
        <br>
        Last name:<br>
        <input type="text" name="lastname" value="<?php echo esc_attr($lastname);?>">
        <button type="submit" name="submit_form" value="1">Submit</button>
    </form> 
    

Comments are closed.