wrdsb / wordpress-plugin-governance

WordPress plugin to simplify adding and maintaining the Policies & Procedures section of the staff intranet.
1 stars 2 forks source link

Add Procedure Number to procedure metadata #7

Open jschumann opened 7 years ago

jschumann commented 7 years ago
    /* Adds a meta box to the post edit screen */
    add_action( 'add_meta_boxes', 'procedures_add_custom_box' );
    function procedures_add_custom_box( $post ) {
        $screens = array( 'post', 'my_cpt' );
        foreach ( $screens as $screen ) {
            add_meta_box(
                'procedures_box_number',            // Unique ID
                'Number',                                                   // Box title
                'procedures_inner_custom_box',      // Content callback
                 $screen                                    // post type
            );
        }
    }

    /* Prints the box content */
    function procedures_number_custom_box( $post ) {
    ?>
       <label for="procedures_number"> Number </label>
        <input name="procedures_number" id="procedures_number" class="postbox" />
    <?php
    }

    add_action( 'save_post', 'procedures_save_postdata' );
    function procedures_save_postdata( $post_id ) {
        if ( array_key_exists('myplugin_field', $_POST ) ) {
            update_post_meta( $post_id,
               '_my_meta_value_key',
                $_POST['myplugin_field']
            );
        }
    }