WP_INSERT_POST工作不正常

时间:2014-09-22 作者:Bhuvnesh Gupta

我问了我关于stackoverflow的问题,但我没有得到任何答案,可能是因为这个问题与Wordpress有关。所以我在这里问。

我正在使用wp_insert_post 函数插入我的帖子,但对我来说效果不好。

这是我的post\\u内容

$content = \'<div class="snippet">
   <strong>Wordpress Tutorial - Jetpack Plugin installieren &amp; 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);
有什么建议可以解决这个问题吗?

2 个回复
SO网友:jzatt

正如Joshua在评论中所建议的,您的代码没有正确转义。

就在“查看原始文章”(在两个片段中)之前target=\'_blank\' 在链接上使用单引号。用双引号替换target="_blank"

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 );

结束