WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a simple Custom Meta Box for a film post.

I need a text box for Title and Director and a textarea for Description.

Everything seemed to working until I added the textarea, I wasn't sure how to create the html.

        <label for="meta_box_desc">Description</label>
        <textarea name="meta_box_desc" id="meta_box_desc" col="100" row="5"><?php echo $desc; ?></textarea>

The text boxes and textarea display in WP but when I click Update I get a white screen

Can anyone see what I'm doing wrong.

    add_action( 'add_meta_boxes', 'cd_meta_box_add' );
    function cd_meta_box_add()
        add_meta_box( 'my-meta-box-id', 'Film Credits', 'cd_meta_box_cb', 'post', 'normal', 'high' );

    function cd_meta_box_cb( $post )
        $values = get_post_custom( $post->ID );

        $title = isset( $values['meta_box_title'] ) ? esc_attr( $values['meta_box_title'][0] ) : '';
        $director = isset( $values['meta_box_director'] ) ? esc_attr( $values['meta_box_director'][0] ) : '';
        $desc = isset( $values['meta_box_desc'] ) ? esc_attr( $values['meta_box_desc'][0] ) : '';

        wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );

            <label for="meta_box_title">Film Title</label>
            <input type="text" name="meta_box_title" id="meta_box_title" value="<?php echo $title; ?>" />
            <label for="meta_box_title">Director</label>
            <input type="text" name="meta_box_director" id="meta_box_title" value="<?php echo $director; ?>" />
            <label for="meta_box_desc">Description</label>
            <textarea name="meta_box_desc" id="meta_box_desc" col="100" row="5"><?php echo $desc; ?></textarea>

    add_action( 'save_post', 'cd_meta_box_save' );
    function cd_meta_box_save( $post_id )
        // Bail if we're doing an auto save
        if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

        // if our nonce isn't there, or we can't verify it, bail
        if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;

        // if our current user can't edit this post, bail
        if( !current_user_can( 'edit_post' ) ) return;

        // now we can actually save the data
        $allowed = array( 
            'a' => array( // on allow a tags
                'href' => array() // and those anchords can only have href attribute

        // Probably a good idea to make sure your data is set
        if( isset( $_POST['meta_box_title'] ) )
            update_post_meta( $post_id, 'meta_box_title', wp_kses( $_POST['meta_box_title'], $allowed ) );
        if( isset( $_POST['meta_box_director'] ) )
            update_post_meta( $post_id, 'meta_box_director', wp_kses( $_POST['meta_box_director'], $allowed ) );
        if( isset( $_POST['meta_box_desc'] ) )
            update_post_meta( $post_id, 'meta_box_desc', wp_kses( $_POST['meta_box_desc'], $allowed ) );
share|improve this question

closed as too localized by brasofilo, toscho Nov 29 '12 at 14:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Please add debug information to your question. – toscho Nov 29 '12 at 12:29
It Works just fine make sure you are within the opening and closing php tags and you dont have <?php inside a php tag – Bainternet Nov 29 '12 at 12:38
Working fine in this end too. The problem is elsewhere. Take a look at the documentation of PHP tags. Close voting as too-localized. – brasofilo Nov 29 '12 at 13:20
It's working now, sorry don't know what I had done to stop it. – user668499 Nov 29 '12 at 13:21