如何在wp_posts表中手动插入带有html代码的字符串

时间:2015-07-13 14:51:38

标签: php mysql wordpress

我正在进行迁移到wordpress并需要手动将数据插入到wp_posts表中。在插入数据时,我使用了mysql_real_escape_string但是html属性被插入了附加的\" 例如:

#Original
<img src="imge.jpg" alt="abcde fghij">

#Inserted to wp_posts using mysql_real_escape_string
<img src="\"imge.jpg"\" alt="\"abcde fghij"\">

这很糟糕,使图像无法正常工作。所以我需要有关如何以wordpress可接受的方式将数据插入wp_posts.post_content的帮助。

3 个答案:

答案 0 :(得分:0)

你试过用单引号吗? 试试这个......

<img src='imge.jpg' alt='abcde fghij'>

答案 1 :(得分:0)

PDO保存数据的方法解决了这个问题。

答案 2 :(得分:0)


您需要使用此功能添加图像内容和其他内容。

// Create post object
$my_post = array(
'post_title' => '#Enter the title#',
'post_content' => '#Enter the Content#'
,'post_status' => 'publish',
'post_author' => 1
);
wp_insert_post( $my_post );
它不会添加任何切片或其他任何内容。

感谢你。