1

I use following functions to add a new rich text editor in admin .

add_action( 'add_meta_boxes', 'adding_new_metaabox' );              
function adding_new_metaabox() 
{   
    add_meta_box('html_myid_61_section', 'ویژگی ها', 'my_output_function');
}

function my_output_function( $post ) 
{
    //so, dont ned to use esc_attr in front of get_post_meta
    $valueeee2 = get_post_meta($_GET['post'], 'PLUGIN_VALUE' , true ) ;
    wp_editor( htmlspecialchars_decode($valueeee2), 'mettaabox_ID_stylee', $settings = array('textarea_name'=>'MyInputNAME') );
}


function save_my_postdata( $post_id ) 
{                   
    if (!empty($_POST['MyInputNAME']))
    {
        $datta=htmlspecialchars($_POST['MyInputNAME']);
        update_post_meta($post_id, 'PLUGIN_VALUE', $datta );
    }
}
add_action( 'save_post', 'save_my_postdata' );  

and I use this code to display the content in the template.

<?php echo get_post_meta($post->ID, "PLUGIN_VALUE", true);?>

but can't display clean content in the post. It looks like this:

<ul><li>Can't</li><li>Display</li><li>good</li></ul>

I don't want to actually display the tags I want to display the content in HTML, similar to the example below:

  • Can't
  • Display
  • good
0

Good question for your first question! Try running the variable through the_contnet Filter - You can use it like this:

$editor_value = get_post_meta( $post->ID, "PLUGIN_VALUE", true ); 
echo apply_filters( 'the_content', htmlspecialchars_decode( $editor_value ) );

I believe what's happening is that whenever you save your postmeta, it is being escaped as it should and converted to special characters htmlspecialchars() so that it can properly be saved to the database. By running the decode it should output the expected HTML.

4
  • @Mortzea Does it still show the same content ( with the HTML ) or was there an error? – Howdy_McGee Dec 4 '14 at 20:49
  • it still show the same content ( with the HTML ) /// in your code where called this variable $editor_value ? – Mortzea Dec 4 '14 at 20:50
  • @Mortzea - I am just storing the value returned from get_post_meta() into a varibale I created called $editor_value so that we can use it inside our filter. See if the edited code works for you. – Howdy_McGee Dec 4 '14 at 20:55
  • no. not working – Mortzea Dec 4 '14 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.