Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenspads/adbf3aa230eef573b1a9bb3fd85dff62 to your computer and use it in GitHub Desktop.
Save stevenspads/adbf3aa230eef573b1a9bb3fd85dff62 to your computer and use it in GitHub Desktop.
For a custom post type named 'listings'
add_action( 'edit_form_after_editor', 'my_new_content_areas' );
add_action( 'save_post', 'save_my_new_content_areas', 10, 2 );
function my_new_content_areas()
{
global $post;
if( 'listings' != $post->post_type )
return;
$editor1 = get_post_meta( $post->ID, 'my_new_editor_1', true);
$editor2 = get_post_meta( $post->ID, 'my_new_editor_2', true);
wp_nonce_field( plugin_basename( __FILE__ ), 'my_new_content_areas_nonce' );
echo '<h2>My New Editor 1</h2>';
echo wp_editor( $editor1, 'my_new_editor_1', array( 'textarea_name' => 'my_new_editor_1' ) );
echo '<h2>My New Editor 2</h2>';
echo wp_editor( $editor2, 'my_new_editor_2', array( 'textarea_name' => 'my_new_editor_2' ) );
}
function save_my_new_content_areas( $post_id, $post_object )
{
if( !isset( $post_object->post_type ) || 'listings' != $post_object->post_type )
return;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !isset( $_POST['my_new_content_areas_nonce'] ) || !wp_verify_nonce( $_POST['my_new_content_areas_nonce'], plugin_basename( __FILE__ ) ) )
return;
if ( isset( $_POST['my_new_editor_1'] ) )
update_post_meta( $post_id, 'my_new_editor_1', $_POST['my_new_editor_1'] );
if ( isset( $_POST['my_new_editor_2'] ) )
update_post_meta( $post_id, 'my_new_editor_2', $_POST['my_new_editor_2'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment