I asked my question on stackoverflow but I did not get any answer, may be because it's the question related to Wordpress.So I am asking it here.
I am using wp_insert_post
function to insert my posts, but it is not working fine for me.
Here is my post_content
$content = '<div class="snippet">
<strong>Wordpress Tutorial - Jetpack Plugin installieren & konfigurieren</strong>
<br/>
<p>Wordpress Online Kurs unter Sie erhalten Tutorials zu den Wordpress Themen, wie Plugins, Theme, SEO ...<a href=;sa=t&url=;ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGFOBEtFiT4f7zq6xl-xTbsW9uIVg target="_blank"></a>
<br />
<a href=;sa=t&url=;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 : FARGO is a beautifully designed and visually ...<a href=;sa=t&url=;ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ target="_blank"></a>
<br />
<a href=;sa=t&url=;ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ rel="nofollow" target='_blank'>See Original Article </a>
</p>
</div>';
When I am adding this as manually it is inserting while I am using cron to insert it just insert post up to "SEO"
Code is :
$my_post = array('post_title'=>'test post','post_content'=>$content);
Any suggestions to solve this?
I asked my question on stackoverflow but I did not get any answer, may be because it's the question related to Wordpress.So I am asking it here.
I am using wp_insert_post
function to insert my posts, but it is not working fine for me.
Here is my post_content
$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/url?rct=j&sa=t&url=http://www.youtube/watch%3Fv%3DzjMtxin-hRA&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGFOBEtFiT4f7zq6xl-xTbsW9uIVg target="_blank"></a>
<br />
<a href=https://www.google/url?rct=j&sa=t&url=http://www.youtube/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/themes/fargo-responsive-creative-wordpress-theme-tfx FARGO is a beautifully designed and visually ...<a href=https://www.google/url?rct=j&sa=t&url=http://www.youtube/watch%3Fv%3DqjKCijxQR1M&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ target="_blank"></a>
<br />
<a href=https://www.google/url?rct=j&sa=t&url=http://www.youtube/watch%3Fv%3DqjKCijxQR1M&ct=ga&cd=CAIyGmExYThkZTljMmU3MDQyZGE6Y29tOmVuOlVT&usg=AFQjCNGlUblc7rKI0OjRLqe1CChEfbpYmQ rel="nofollow" target='_blank'>See Original Article </a>
</p>
</div>';
When I am adding this as manually it is inserting while I am using cron to insert it just insert post up to "SEO"
Code is :
$my_post = array('post_title'=>'test post','post_content'=>$content);
Any suggestions to solve this?
Share Improve this question edited Sep 22, 2014 at 6:29 Bhuvnesh Gupta asked Sep 22, 2014 at 5:20 Bhuvnesh GuptaBhuvnesh Gupta 3112 gold badges9 silver badges21 bronze badges 4 |2 Answers
Reset to default 1As Joshua suggested in his comment, your code isn't escaped properly.
Just before "See Original Article" (in both snippets) you have target='_blank'
on your links with single quotes. Replace that with double quotes target="_blank"
This is general idea of how wp_insert_post
works
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 );
$array
array. Going down this thought process it would need to be$array = array('$content');
as a quick troubleshoot. Can you post all the code please? EDIT I also see that yourhref
content is not in double quotes, I'm not sure if it would still work but according to my understanding it's best practice to do so. – Joshua Commented Sep 22, 2014 at 6:21