I'm inserting posts by wp_insert_post function. It works like first a post is created to get its id then an image is attached to that post id. I attach images by media sideload function. Here is the whole code module on which I'm working on :HERE . Initially post content is left blank.
$new_post = array(
'post_title' => $title,
'comment_status' => 'open',
'post_name' => $slug,
'post_content' => '',
'post_status' => 'draft',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => 2,
'post_type' => 'post',
'post_category' => $cat_ids
);
$post_id = wp_insert_post($new_post);
When images is uploaded and attached after that I add a variable $content as below and update the post.
$content = $link[$i].'<br>'.'<img src="'.$src.'" alt="'.$img_title.'" title="'.$img_title.'" class="alignnone size-full wp-image-'.$img_id.'" width="500"/>';
$link[$i] contains the original url of that image.
$src = wp_get_attachment_url( $img_id );
Everything works fine but problem is when I see the same post in the editor, it only shows as url of image. Rest is not displayed. I tried these:
Changed theme if css posing that problem. Result was same content was displayed as above url and no image tags in post editor.
I changed the code after
<br>
, as '1234 qwe asd zdc'. Resulted asurl1234 qwe asd zdc
<br>
doesn't seem to work. There was no break.Echoed direct
$content
variable without changing anything, on a blankfile.php
, displayed url and image correctly.
How to resolve this thing? I have been trying this for whole day but no success.
UPDATE: What I have found is probably, the post is updating but not taking new content in line 52 :here