在post_content中使用HTML的WordPress wp_insert_post正在添加\ r \ n

时间:2014-05-22 20:23:37

标签: php html wordpress tinymce sanitization

我在WordPress之外创建一个脚本来插入新帖子,而WordPress正在以一种奇怪的方式清理我的帖子。

我还将修改WordPress之外的帖子。

我正在为post_content textarea使用TinyMCE。

我使用所有WordPress功能,包括:

include('../wp-config.php');

以下是我的代码,可以插入我的帖子,但每个新行都有\ r \ n:

$listing_phase = strtoupper($_POST['listing_phase']);
$listing_title = strtoupper($_POST['listing_title']);
$listing_description = $_POST['listing_description'];
$new_listing = array(
    'post_title'    => $listing_title,
    'post_name'     => str_replace('-', ' ', $listing_title),
    'post_content'  => $listing_description,
    'tax_input'     => array('property-status' => $listing_phase),
    'post_status'   => 'publish',
    'post_type'     => 'property',
    'post_author'   => 1
);
$listing_id = wp_insert_post($new_listing);

以下是TinyMCE提交的HTML:

<p>Studio</p>
<ul>
<li>Free Electric</li>
</ul>

这就是数据库中的内容:

<p>Studio</p>\r\n<ul>\r\n<li>Free Electric</li>\r\n</ul>

在尝试修改帖子时,我正在显示the_content();和\ r \ n正在调用get_posts();

如何向WordPress的wp_insert_post函数提交基本HTML内容并获取要在以后查看或修改的内容?

WordPress Display

谢谢!

1 个答案:

答案 0 :(得分:1)

 $listing_description = str_replace('\r\n','',$_POST['listing_description']);
相关问题