problem with esc_textarea and get_post_meta
-
Hi,
I have a custom meta box in which I want to be able to enter meta tags so I need it to accept html and quotes. I have it accepting them but then when I run my function in header.php to echo them is where I am having problems. I got them to work in the dashboard by using esc_textarea but when I use this to echo out the post meta I get an error.
htmlspecialchars() expects parameter 1 to be string, array given
When I don’t use esc_textarea() I get an empty string for the array key even though I know it’s there looking in the database so I’m guessing it is because of trying to output
<meta name='whatever' content='whatever'>
with the open and closing tags.Here is my function in functions.php that I call in header.php:
function get_facebook_meta() { global $post; $my_facebook_meta = esc_textarea(get_post_meta($post->ID, '_my_meta_facebook', false)); //$my_facebook_meta = get_post_meta($post->ID, '_my_meta_facebook', false); echo $my_facebook_meta['facebook']; //print_r($my_facebook_meta); }
I left in the commented lines where I’m trying to figure this out. I also tried both true and false as the 3rd param even though false makes no sense since it is returning a serialized array.
I’m sure the error I’m getting is because the data is a serialized array but I’d like to get around this so I can use the html tags.
Thanks
- The topic ‘problem with esc_textarea and get_post_meta’ is closed to new replies.