Support Forum
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:
Is it possible to save this as raw html?
Thanks in advance!
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.
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:
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?
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);
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 ) );
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
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()?
Yes, im using rwmb_meta().
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.
Yeah i will do this today or tomorrow, thank you for the help.
Hi,
The problem happens because the code used the function esc_attr()
, it escapes HTML code and returns only a string that's why we only see the <ul><li>
tag.
I've just removed it then we can see the list as well.
$benefits = $_POST['benefits'];
$aufgaben = $_POST['aufgaben'];
$fachwissen = $_POST['fachwissen'];
Or you can keep the function esc_attr()
then use the function htmlspecialchars_decode()
to convert special HTML entities back to characters.
/* Aufgaben */
function kie_job_get_aufgaben(){
return htmlspecialchars_decode( strip_tags(rwmb_meta( 'kie_aufgaben', get_the_ID() ), '<ul><li></ul></li>') );
}