longnguyenwp

Fake post excerpt

Mar 30th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 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( 'book', 'excerpt' ); // 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, 'book', FILTER_SANITIZE_NUMBER_INT );
  9. // $post_content = get_post_field( 'post_excerpt', $post_id );
  10. $meta_boxes[] = [
  11. 'title' => 'Excerpt for Book post type', // this is the Field Group Title
  12. 'post_types' => 'book', // 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. ],
  20. // Custom style to overwrite the editor style set by WordPress.
  21. [
  22. 'type' => 'custom_html',
  23. 'std' => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>',
  24. ],
  25. ],
  26. ];
  27. return $meta_boxes;
  28. } );
  29. // Set the value for the 'excerpt' field.
  30. add_filter( 'rwmb_content_field_meta', function() {
  31. $post_id = filter_input( INPUT_GET, 'book', FILTER_SANITIZE_NUMBER_INT ); //assumed I should use book the CPT instead of 'post' here
  32. return get_post_field( 'post_excerpt', $post_id ); // assumed I should use 'post_excerpt instead of 'post_content here
  33. } );
  34. // did not think the following were necessary in this case so commented them out
  35. // Do not save 'content' field to post meta.
  36. add_filter( 'rwmb_content_value', '__return_empty_string' );
Add Comment
Please, Sign In to add comment