Insert wysiwyg field value to post content

Support General Insert wysiwyg field value to post content

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36888
    JaakkoJaakko
    Participant

    Hi, I have this code snippet working for a post type, it inserts wysiwyg field as the posts content. How can I use this on another post type? I tried creating a new snippet and using the same snippet but changing the post type values but it doesn't work.

    <?php 
    
    // Remove the editor. Change 'post' to your custom post type.
    add_action( 'init', function () {
        remove_post_type_support( 'verkkokurssi', 'editor' );
    } );
    
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        // Get the current post content and set as the default value for the wysiwyg field.
        $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        $post_content = get_post_field( 'post_content', $post_id );
    
        $meta_boxes[] = [
            'title'      => 'Verkkokurssi',
            'post_types' => 'verkkokurssi', // Change 'post' to your custom post type.
            'style'      => 'seamless',
            'fields'     => [
                // Register a wysiwyg field of which the content is saved as post content.
                [
                    'type' => 'wysiwyg',
                    'name'       => 'Kurssin kuvaus',
                    'columns' => 12,
                    'id'         => 'content',
                    'std'        => $post_content,
                    'options' => [
                        'media_buttons' => false,
                    ],
                    'save_field' => false,
                ],
                // 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 'content' field.
    add_filter( 'rwmb_content_field_meta', function() {
        $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
        return get_post_field( 'post_content', $post_id );
    } );
    #36900
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The code still works as well on my demo site with a custom post type. Can you please share some screenshots of the issue? And share the code that creates the CPT on your site?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.