Create Custom Meta Box wordpress 4.6.1

I tried to create a new custom meta box for my wordpress custom template.
It seams that the wordpress function that allowed this precedently have changed on the version 4.6.1 of WP and is not effective anymore. Does anybody have a clue on how I can managed to make this following code work again?

<?php
   function add_custom_meta_box()
{
    add_meta_box("demo-meta-box", "Raison Sociale du Partenaire","custom_meta_box_markup", "partners", "advanced", "high", null);
}
add_action("add_meta_boxes", "add_custom_meta_box");

function custom_meta_box_markup($object)
{
    wp_nonce_field(basename(__FILE__), "meta-box-nonce");

    ?>
        <div>
            <label for="meta-box-text">Raison Sociale du Partenaire  :&nbsp;</label><br>
            <input name="meta-box-text" type="text" value="<?php echo get_post_meta($object->ID, "meta-box-text", true); ?>" placeholder="Raison Sociale de la personne / Raison sociale de la structure" style="width:450px;" required autofocus>*

        </div>
    <?php
}


function save_custom_meta_box($post_id, $post, $update) {
    if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
        return $post_id;

    if(!current_user_can("edit_post", $post_id))
        return $post_id;

    if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
        return $post_id;

    $slug = "partners";
    if($slug != $post->post_type)
        return $post_id;

    $meta_box_text_value = "";
    $meta_box_dropdown_value = "";
    $meta_box_checkbox_value = "";

    if(isset($_POST["meta-box-text"]))
    {
        $meta_box_text_value = $_POST["meta-box-text"];
    }
    update_post_meta($post_id, "meta-box-text", $meta_box_text_value);
}
add_action("save_post", "save_custom_meta_box", 10, 3);
?>

Thanks for your future help !

Kevin

0

Answers


Please signup or login to answer this question.

Signup for an account and start participating in our site today!




Social Signup

You can also login with your Facebook, Twitter or Linkedin account

Log in with Facebook