• I’m not sure why I’m getting this error in my backend:

    View post on imgur.com

    I noted the line in the code that the error references. It’s the 13th line of code here though.

    The error goes away after I select and save one of the choices in the dropdown box.

    I’m new to php/wordpress so I’m not sure what this error means.

    function cd_meta_box_add() {
    	add_meta_box (
    		'postTags', // Unique ID
    		'Post Tags', // Title
    		'post_tags_metabox', // Callback Function
    		'post', // Admin page (or post type)
    		'side', // Context
    		'high' // Priority
    		);
    }
    add_action('add_meta_boxes', 'cd_meta_box_add' );
    
    function post_tags_metabox( $post) {
    	$values = get_post_meta( $post->ID );
    	$selected = isset( $values['post_tag_select'] ) ? esc_attr( $values['post_tag_select'][0] ) : ”; // This is line 165. Error reference.
    
    	wp_nonce_field( 'post_tags_metabox_nonce', 'meta_box_nonce' );
    	?>
    	<p>
            <label for="post_tag_select">Post Tag</label>
            <select name="post_tag_select" id="post_tag_select">
    			<option value=" " <?php selected( $selected, ' ' ); ?>> </option>
                <option value="guide" <?php selected( $selected, 'guide' ); ?>>Guide</option>
                <option value="video" <?php selected( $selected, 'video' ); ?>>Video</option>
    			<option value="strat" <?php selected( $selected, 'strat' ); ?>>Strat</option>
    			<option value="tips" <?php selected( $selected, 'tips' ); ?>>Tips</option>
    			<option value="theory" <?php selected( $selected, 'theory' ); ?>>Theory</option>
    			<option value="beta" <?php selected( $selected, 'beta' ); ?>>Beta</option>
            </select>
    	</p>
    	<?php
    }
    add_action( 'save_post', 'post_tags_metabox_save' );
    function post_tags_metabox_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'], 'post_tags_metabox_nonce' ) ) return; 
    
        // if our current user can't edit this post, bail
        if( !current_user_can( 'edit_post', $post_id ) ) return;  
    
    	    if( isset( $_POST['post_tag_select'] ) )
            update_post_meta( $post_id, 'post_tag_select', esc_attr( $_POST['post_tag_select'] ) );
    }
  • The topic ‘Metabox is throwing up an error notice?’ is closed to new replies.