black friday sale

Custom Fields
Re-Envisioned
Support General Add/update post meta with raw html to WYSIWYG Field

  • Creator
    Topic
  • #20558
    Resolved Bernhard Niemann
    Participant

    Hello,

    i want to add/update content to a wysiwyg field created with metabox. When Im doing this it saves the html content as normal text, not as html. Watch the following screen to understand:

    https://ibb.co/T46kBkb

    Is it possible to save this as raw html?

    Thanks in advance!

Viewing 10 replies - 1 through 10 (of 11 total)
  • Author
    Replies
  • #20560
    Long Nguyen
    Moderator

    Hi Bernhard,

    If you want to insert some HTML code to the field WYSIWYG, please switch to the tab Text then type the HTML code. See my screenshot https://share.getcloudapp.com/P8ueQpLJ.

    #20568
    Bernhard Niemann
    Participant

    Yes I know how to do this, but if I add raw html code by php like this:

    add_post_meta($post_id, 'kie_arbeitsort_front', $arbeitsort, false);

    it is not possible to add raw html content. It always save the html content as normal text, which leads to the content to be saved as something like this:

    https://ibb.co/HH6w8s8

    #20569
    Long Nguyen
    Moderator

    Hi,

    After creating a field WYSIWYG, you should use the function update_post_meta(). It updates the HTML content in the tab Text as well. See my screen record https://www.loom.com/share/d1f5a83412454a999316b6e4f4bef292.

    Could you please share the code which creates the field and HTML content updated if the problem still happens?

    #20594
    Bernhard Niemann
    Participant

    Creating the field:

    function kie_jobs_aufgaben_metabox( $meta_boxes ) {
    
        $prefix = 'kie_';
    
        $meta_boxes[] = array(
            'id' => 'aufgaben',
            'title' => esc_html__( 'Aufgaben', 'kie-stellenboerse' ),
          'post_types' => array( 'jobs' ),
            'context' => 'after_title',
          'priority' => 'high',
            'autosave' => true,
          'fields' => array(
            array(
                'name'    => 'Aufgaben',
                'id'      => $prefix . 'aufgaben',
                'type'    => 'wysiwyg',
                'add_to_wpseo_analysis' => true,
                'class' => 'kie_metabox_textarea',
                'raw'     => false,
                'options' => array(
                    'textarea_rows' => 4,
                    'teeny'         => true,
                ),
            ),
          ),
        );
    
        return $meta_boxes;
    }

    Updating Post Meta:
    update_post_meta($post_id, 'kie_aufgaben', wp_kses_post($aufgaben), false);

    #20596
    Long Nguyen
    Moderator

    Hi,

    Your code works as well, see the screen record again https://www.loom.com/share/1b58e921914348eeac49aefe4fb5610e.

    add_filter( 'rwmb_meta_boxes', 'kie_jobs_aufgaben_metabox' );
    function kie_jobs_aufgaben_metabox( $meta_boxes ) {
    
        $prefix = 'kie_';
    
        $meta_boxes[] = array(
            'id' => 'aufgaben',
            'title' => esc_html__( 'Aufgaben', 'kie-stellenboerse' ),
            'post_types' => array( 'post' ),
            'context' => 'after_title',
            'priority' => 'high',
            'autosave' => true,
            'fields' => array(
                array(
                    'name'    => 'Aufgaben',
                    'id'      => $prefix . 'aufgaben',
                    'type'    => 'wysiwyg',
                    'add_to_wpseo_analysis' => true,
                    'class' => 'kie_metabox_textarea',
                    'raw'     => false,
                    'options' => array(
                        'textarea_rows' => 4,
                        'teeny'         => true,
                    ),
                ),
            ),
        );
    
        return $meta_boxes;
    }
    
    $meta_value = '<h2 style="color: green">Test HTML tag</h2>';
    update_post_meta( 4, 'kie_aufgaben', wp_kses_post( $meta_value ) );
    #21145
    Bernhard Niemann
    Participant

    Hello,

    sorry for my late response. Please see the video. There you can see, that it isnt working, maybe because of tinymce.
    https://streamable.com/extxx2

    #21163
    Long Nguyen
    Moderator

    Hi,

    The function update_post_meta() updates the meta value in the backend as well. The issue is it does not display the HTML tag in the frontend. Could you please check the code which shows the field value in the frontend? Is it rwmb_meta()?

    #21166
    Bernhard Niemann
    Participant

    Yes, im using rwmb_meta().

    #21169
    Long Nguyen
    Moderator

    Hi,

    This problem is so weird, please follow this guide to know how to create the staging site https://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/.

    Then share the credentials (Admin site and FTP account) via this form https://metabox.io/contact/. I will check it out.

    #21207
    Bernhard Niemann
    Participant

    Yeah i will do this today or tomorrow, thank you for the help.

Viewing 10 replies - 1 through 10 (of 11 total)
  • You must be logged in to reply to this topic.