admin管理员组

文章数量:1390519

How can i make this meta box please help?

function add_custom_meta_box1()
{
         add_meta_box(
                'meta-box1',
                'Featured Image Settings ',
                'custom_meta_box_callback1',
                'page',
                'side',
                'low'
                );
}
add_action('add_meta_boxes', 'add_custom_meta_box1');

function custom_meta_box_callback1(){

    global $post;
    wp_nonce_field( basename(__FILE__ ), 'custom_meta1_nonce');
    $custom_stored_meta1 = get_post_meta( $post->ID, 'drop_down', true );

    ?>
        <li>
            <label>Background Fit:</label>
            <br>
            <select id="emeta[]" name="emeta[]">
                <option>Cover</option>
                <option>Contain</option>
                <option>Normal</option>
            </select>
            <br>
            <label>Background Position:</label>
            <br>
            <select id="emeta[]" name="emeta[]">
                <option>Center Top</option>
                <option>Center right</option>
                <option>Center Bottom</option>
                <option>Center Center</option>
                <option>Left Top</option>
                <option>Left Center</option>
                <option>Left Bottom</option>
                <option>Right Top</option>
                <option>Right Center</option>
                <option>Right Bottom</option>
                <option>Custom</option>

            </select>
            <br>
            <label>Background Repeat:</label>
            <br>
            <select id="emeta[]" name="emeta[]">
                <option>No Repeat</option>
                <option>Repeat</option>
                <option>Repeat-X</option>
                <option>Repeat-Y</option>
            </select>
            <label>Value:</label><input size="20" type="text" value="<?php echo esc_attr( $custom_stored_meta1); ?>" name="emetad[]" id="emetad[]">
        </li>




    <?php
}

function custom_meta1_save($post_id){
    //checks save status
    $is_autosave = wp_is_post_autosave( $post_id);
    $is_revision = wp_is_post_revision( $post_id);
    $is_valid_nonce = ( isset( $_POST[ 'custom_meta1_nonce' ] ) && wp_verify_nonce( $_POST['custom_meta1_nonce' ],basename( __FILE__)) ) ? 'true': 'false';
    if ( ! current_user_can( 'edit_post', $post_id ) ) {
        return;
    }
    //Exit scripts depending on save status
    if( $is_autosave || $is_revision || !$is_valid_nonce ){
        return;
    }

    if( isset( $_POST['drop_down'] ) ){
        update_post_meta( $post_id , 'drop_down', sanitize_text_field( $_POST[ 'drop_down'] ) );
    }


}
add_action('save_post', 'custom_meta1_save');

本文标签: