WordPress.org

Support

Support » How-To and Troubleshooting » problem with esc_textarea and get_post_meta

problem with esc_textarea and get_post_meta

Viewing 3 replies - 1 through 3 (of 3 total)
  • Once again, I work on figuring something out for hours and then figure it out after posting the question.

    get_post_meta was returning the array with the value intact. I just used esc_textarea on the single value before echoing it instead of trying to use it on the get_post_meta function.

    function get_facebook_meta()
    {
    	global $post;
    	$my_facebook_meta = get_post_meta($post->ID, '_my_meta_facebook', true);
    	echo esc_textarea($my_facebook_meta['facebook']);
    }

    I’ll mark it resolved but any suggestions on doing this better are appreciated.

    Thanks

    I thought the problem was resolved.

    I can’t seem to put in double quotes or slashes for the html because add_post_meta() is stripping them out.

    Can anyone tell me how to stop that? How would I protect the metabox data from stripping? I tried using addslashes() but that causes the data to not get written to the database at all.

    Here is my code for saving the data:

    $current_data = esc_textarea(get_post_meta($post_id, '_my_meta_facebook', TRUE)); 
    
        $new_data = $_POST['_my_meta_facebook'];
    
        //$new_data = addslashes($new_data);
        //my_meta_facebook_clean($new_data);
    
        if ($current_data)
        {
            if (is_null($new_data)) delete_post_meta($post_id,'_my_meta_facebook');
            else update_post_meta($post_id,'_my_meta_facebook',addslashes($new_data));
        }
        elseif (!is_null($new_data))
        {
            add_post_meta($post_id,'_my_meta_facebook', addslashes($new_data), TRUE);
        }
    
        return $post_id;

    I need to add this with slashes and double quotes intact:
    <meta name="fb:something" content="whatever"/>

    Thanks

    Well I thought the problem was resolved but it’s not.

    When saving meta data with a custom metabox add_post_meta() is stripping out double quotes and the closing ‘/’ for the closing tag.

    I need to be able to save this:
    <meta name="fb:whatever" content="somecontent"/>

    How do I protect the string so add_post_meta() won’t strip it?
    I tried addslashes() but that ends up causing an error somewhere and stoping it from writing anything to the database at all.

    here is my save code excluding the admin check part.

    $current_data = esc_textarea(get_post_meta($post_id, '_my_meta_facebook', TRUE)); 
    
        $new_data = $_POST['_my_meta_facebook'];
    
        //$new_data = addslashes($new_data);
        //my_meta_facebook_clean($new_data);
    
        if ($current_data)
        {
            if (is_null($new_data)) delete_post_meta($post_id,'_my_meta_facebook');
            else update_post_meta($post_id,'_my_meta_facebook',addslashes($new_data));
        }
        elseif (!is_null($new_data))
        {
            add_post_meta($post_id,'_my_meta_facebook', addslashes($new_data), TRUE);
        }
    
        return $post_id;

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘problem with esc_textarea and get_post_meta’ is closed to new replies.
Skip to toolbar