我问了我关于stackoverflow的问题,但我没有得到任何答案,可能是因为这个问题与Wordpress有关。所以我在这里问。
我正在使用wp_insert_post
函数插入我的帖子,但对我来说效果不好。
这是我的post\\u内容
$content = \'<div class="snippet">
<strong>Wordpress Tutorial - Jetpack Plugin installieren & konfigurieren</strong>
<br/>
<p>Wordpress Online Kurs unter http://wordpress-online-kurs.de Sie erhalten Tutorials zu den Wordpress Themen, wie Plugins, Theme, SEO ...<a href=https://www.google.com/url?rct=j&sa=t&url=http://www.youtube.com/watch%3Fv%3DzjMtxin-hRA&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGFOBEtFiT4f7zq6xl-xTbsW9uIVg target="_blank"></a>
<br />
<a href=https://www.google.com/url?rct=j&sa=t&url=http://www.youtube.com/watch%3Fv%3DzjMtxin-hRA&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGFOBEtFiT4f7zq6xl-xTbsW9uIVg rel="nofollow" target=\'_blank\'>See Original Article </a>
</p>
</div>
<div class="snippet">
<strong>Preview Fargo - Responsive Creative WordPress Theme TFx</strong>
<br/>
<p>
Preview and Download : http://fxtheme.com/themes/fargo-responsive-creative-wordpress-theme-tfx FARGO is a beautifully designed and visually ...<a href=https://www.google.com/url?rct=j&sa=t&url=http://www.youtube.com/watch%3Fv%3DqjKCijxQR1M&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ target="_blank"></a>
<br />
<a href=https://www.google.com/url?rct=j&sa=t&url=http://www.youtube.com/watch%3Fv%3DqjKCijxQR1M&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ rel="nofollow" target=\'_blank\'>See Original Article </a>
</p>
</div>\';
当我手动添加它时,它是插入的,而我使用cron插入它时,只需将帖子插入到“SEO”
代码为:
$my_post = array(\'post_title\'=>\'test post\',\'post_content\'=>$content);
有什么建议可以解决这个问题吗?
SO网友:Shaikh Nadeem
这是如何wp_insert_post
作品
if(isset($_POST[\'submit\']) && !empty($_POST[\'submit\']))
$title = sanitize_text_field( $_POST[\'title\'] );
$content = sanitize_text_field( $_POST[\'content\'] );
$args = array(
\'post_title\' => $title,
\'post_content\' => $content, // this is your post content
\'post_status\' => \'publish\', //publish, draft
\'post_type\' => \'post\', //write here your post type it may be post , or your custom post type
);
$posts = wp_insert_post( $args );