Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Remove the editor. Change 'post' to your custom post type.
- add_action( 'init', function () {
- remove_post_type_support( 'book', 'excerpt' ); // also tried to remove the post_content editor for the CPT, but it still shows
- } );
- add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
- // was not sure if the following 3 lines were necessary so commented them out, did not work either way
- // Get the current post content and set as the default value for the wysiwyg field.
- // $post_id = filter_input( INPUT_GET, 'book', FILTER_SANITIZE_NUMBER_INT );
- // $post_content = get_post_field( 'post_excerpt', $post_id );
- $meta_boxes[] = [
- 'title' => 'Excerpt for Book post type', // this is the Field Group Title
- 'post_types' => 'book', // Change 'post' to your custom post type.- done
- 'fields' => [
- // Register a wysiwyg field of which the content is saved as post content.
- [
- 'type' => 'wysiwyg',
- 'id' => 'excerpt', // This is the must!
- 'name' => 'Reason for snippet', // label for the custom field
- ],
- // Custom style to overwrite the editor style set by WordPress.
- [
- 'type' => 'custom_html',
- 'std' => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
- ],
- ],
- ];
- return $meta_boxes;
- } );
- // Set the value for the 'excerpt' field.
- add_filter( 'rwmb_content_field_meta', function() {
- $post_id = filter_input( INPUT_GET, 'book', FILTER_SANITIZE_NUMBER_INT ); //assumed I should use book the CPT instead of 'post' here
- return get_post_field( 'post_excerpt', $post_id ); // assumed I should use 'post_excerpt instead of 'post_content here
- } );
- // did not think the following were necessary in this case so commented them out
- // Do not save 'content' field to post meta.
- add_filter( 'rwmb_content_value', '__return_empty_string' );
Add Comment
Please, Sign In to add comment