Using wp_insert_post with special UTF8 characters
-
How can one filter/encode UTF8 characters, such as foreign language characters, properly before passing them into the wp_insert_post() function? I’m looking to write a plugin that uses the wp_insert_post() function, but I’m having trouble with how to filter/escape characters properly.
For instance, the foreign language characters o and u with umlaut (?, ü). These end up being funky in my post title and post content.
For instance,
<? $post_tags = array('?dün?', 'müzik'); $post_tags = array_map('utf8_uri_encode', $post_tags); $post_array = array('post_content'=>utf8_uri_encode('Go ?dün? müzik'), 'post_title'=>utf8_uri_encode('?dün? müzik'), 'post_date'=>date("Y-m-d H:i:s"), 'post_author'=>0, 'post_status'=>'publish', 'tags_input'=>$post_tags); $inserted_post_id = wp_insert_post($post_array); ?>
If I don’t apply any filtering, the foreign language characters seem to not show up at all. If I apply utf8_encode(), ‘?dün? müzik’ displays as ‘?d?n? m?zik’. If I apply the WordPress formatting function utf8_uri_encode, it shows up as ‘dn%f6%fc%e7 mzik’.
If I manually post this phrase, it seems to display fine. What filtering/escaping/encoding is WordPress applying to the dashboard input that I should use on the parameters in my plugin?
- The topic ‘Using wp_insert_post with special UTF8 characters’ is closed to new replies.