2011-02-14 30 views
1

作爲標題,如何防止wp不在後期編碼html?如何防止Wordpress在後期編碼HTML

目前我只需要防止「&」變化& 結果必須看起來像與選定的HTML標籤模式的編輯器。

$content = $wpdb->get_row("SELECT post_content FROM $wpdb->posts WHERE ID=xxx"); 
$content = str_replace('amp;','',$content->post_content);//remove amp; 

$wpdb->query("UPDATE $wpdb->posts SET post_content = $content WHERE ID = xxx;"); 

但該代碼仍然編碼html。

更新: 以及如何實現內容過濾(防止一些文本編碼)協同wp_insert_post()功能

更新[解決]:stackexchange

$content = get_post_field('post_content', XXX, 'raw'); 
$content = str_replace('amp;', '', $content); 
$wpdb->update($wpdb->posts, array('post_content' => $content), array('ID' => XXX)); 
+0

只是一個指針,你可能想嘗試http://wordpress.stackexchange.com,完全致力於WordPress,可能會更快爲你:-) – 2011-02-14 09:25:07

+0

謝謝。但目前沒有人給出答案:) – Andy 2011-02-14 10:39:17

回答

3
<?php $content = htmlentities(html_entity_decode($content)); ?> 

這段代碼打印HTML標籤,然後解碼HTML實體(如&amp;&)。

哦,有wp_insert_post(),這樣做:在博客文章

function escape_html_func($attrs, $content = "") { 
    return htmlentities(html_entity_decode($content)); 
} 
add_shortcode('escape', 'escape_html_func'); 

[escape]<span>Hello!</span>[/escape]

// Create post object 
$my_post = array(
    'post_content' => $content, 
    'post_id' => POST_ID # update the post with the same ID as POST_ID 
); 

您可以使用轉義功能的短代碼。這是你的內容過濾器的意思嗎?