hartsook

wysiwyg metabox excerpt replacement

Mar 30th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. // Remove the editor. Change 'post' to your custom post type.
  2. add_action( 'init', function () {
  3. remove_post_type_support( 'code-snippet', 'excerpt' , 'post_content' ); // also tried to remove the post_content editor for the CPT, but it still shows
  4. } );
  5. add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
  6. // was not sure if the following 3 lines were necessary so commented them out, did not work either way
  7. // Get the current post content and set as the default value for the wysiwyg field.
  8. // $post_id = filter_input( INPUT_GET, 'code-snippet', FILTER_SANITIZE_NUMBER_INT );
  9. // $post_content = get_post_field( 'post_excerpt', $post_id );
  10. $meta_boxes[] = [
  11. 'title' => 'Code Snippet Before', // this is the Field Group Title
  12. 'post_types' => 'code-snippet', // Change 'post' to your custom post type.- done
  13. 'fields' => [
  14. // Register a wysiwyg field of which the content is saved as post content.
  15. [
  16. 'type' => 'wysiwyg',
  17. 'id' => 'excerpt', // This is the must!
  18. 'name' => 'Reason for snippet', // label for the custom field
  19. 'std' => $post_excerpt, // was not sure what to put here
  20. ],
  21. // Custom style to overwrite the editor style set by WordPress.
  22. [
  23. 'type' => 'custom_html',
  24. 'std' => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
  25. ],
  26. ],
  27. ];
  28. return $meta_boxes;
  29. } );
  30. // Set the value for the 'excerpt' field.
  31. add_filter( 'rwmb_content_field_meta', function() {
  32. $post_id = filter_input( INPUT_GET, 'code-snippet', FILTER_SANITIZE_NUMBER_INT ); //assumed I should use code-snippet the CPT instead of 'post' here
  33. return get_post_field( 'post_excerpt', $post_id ); // assumed I should use 'post_excerpt instead of 'post_content here
  34. } );
  35. // did not think the following were necessary in this case so commented them out
  36. // Do not save 'content' field to post meta.
  37. // add_filter( 'rwmb_content_value', '__return_empty_string' );
Add Comment
Please, Sign In to add comment