Save Wysiwyg content as post_content
- This topic has 3 replies, 4 voices, and was last updated 4 years, 9 months ago by
Long Nguyen.
-
AuthorPosts
-
March 10, 2017 at 4:05 AM #5234
clientservices
ParticipantIs it possible to save a Wysiwyg field's content into the post_content.
Also if i created a Wysiwyg field, could i and how will i set the default value as post_content. (assuming i already had content in wp default Wysiwyg)Thank you
March 10, 2017 at 9:01 AM #5243Anh Tran
KeymasterHi, to save wysiwyg field's content into the post_content, you have to do the trick:
- Setup the post type not to support editor (using this function https://codex.wordpress.org/Function_Reference/remove_post_type_support)
- Set the wysiwyg field the id =content
.If you do that, you can set the
std
value as the post content by querying the post content.This is the code: https://gist.github.com/rilwis/eacd78b507df951cb0450ebd38ee14ac
PS: this question is asked quite frequently, so I created a tutorial for it here with more details: https://metabox.io/docs/save-wysiwyg-content-post-content/
July 23, 2020 at 7:21 AM #20919[email protected]
ParticipantI have this set up, and in the WYSIWYG editor for the content field I can set a link on some text, but after saving the post the link is removed. What am I missing?
You had me add a custom html field to the Field Group with the following:
<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>'
the full code for the Field Group is:
<?php add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' ); function your_prefix_register_meta_boxes( $meta_boxes ) { $prefix = ''; $meta_boxes[] = array ( 'title' => esc_html__( 'Code Snippet Before', 'text-domain' ), 'id' => 'code-snippet-before', 'post_types' => array( 0 => 'code-snippet', ), 'context' => 'after_title', 'priority' => 'high', 'fields' => array( array ( 'id' => $prefix . 'content', 'name' => esc_html__( 'Reason for snippet', 'text-domain' ), 'type' => 'wysiwyg', 'desc' => '###Why did I need to use this? This field is also used as the Excerpt for the post.###', 'class' => 'reason-for-snippet', ), array ( 'id' => $prefix . 'what-it-does', 'name' => esc_html__( 'What It Does', 'text-domain' ), 'type' => 'wysiwyg', ), array ( 'id' => $prefix . 'actual-code-snippet', 'name' => esc_html__( 'Actual Code Snippet', 'text-domain' ), 'type' => 'wysiwyg', 'sanitize_callback' => 'none', ), array ( 'id' => $prefix . 'before-the-snippet', 'type' => 'single_image', 'name' => esc_html__( 'Before the snippet', 'text-domain' ), ), array ( 'id' => $prefix . 'after-the-snippet', 'type' => 'single_image', 'name' => esc_html__( 'After the snippet', 'text-domain' ), ), array ( 'id' => $prefix . 'custom_html_sbvmvz193m', 'type' => 'custom_html', 'std' => '<style>#wp-content-editor-tools{background:none;padding-top:0;}</style>\'', ), ), 'style' => 'seamless', ); return $meta_boxes; }
July 23, 2020 at 11:32 AM #20927Long Nguyen
Moderator@hartsook
You need to add the default content for the field
wysiwyg
and set the value for the 'content' custom field. For your case, the code would be https://pastebin.com/erjmfhht.Remember change the post to your post type and follow the code in the documentation https://docs.metabox.io/save-wysiwyg-content-post-content/.
-
AuthorPosts
- You must be logged in to reply to this topic.