certainlyakey
7/6/2014 - 4:51 PM

Wordpress - use metabox values as post title

Wordpress - use metabox values as post title

add_action( 'submitpost_box', 'hidden_type_title' );

function hidden_type_title() {
	global $current_user, $post, $post_type;
	if( $post->post_type == 'cover' ) {
		$cover_issue = get_post_meta( $post->ID, 'wos_covers_issue', true );
		$cover_title = get_post_meta( $post->ID, 'wos_covers_presstitle', true );
		if ($cover_issue && $cover_title) {
			echo '<input type="hidden" name="post_title" value="'.$cover_title.' '.$cover_issue.'" id="title" />';
		} else {
		//Change the title of posts with CPT that doesn't support 'title' feature from default 'Auto Draft' to 'Cover'
			echo '<input type="hidden" name="post_title" value="Cover" id="title" />';
		}
	}
}