tag doesn't display in post content when added via wp_insert_post function
-
I have a wordpress blog as a photoblog. I developed a small plugin of my own using wp insert post function to make post programmatically. It uploads image from my server and makes a post. Problem is, it doesn’t display image inside the post but there is that same image as post thumbnail which confirms it uploads images without any problem. Doesn’t display image inside the post means there is no img tag inside. But if I provide any other string to post_content array element, it displays it. Here is everything of what I am talking about:
$auto_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' => 1, 'post_type' => 'post', 'post_category' => $cat_ids, ); $auto_post_id = wp_insert_post($auto_new_post); $src = wp_get_attachment_url( $id ); $content = '<img src="'.$src.'" alt="'.$title.'" title="'.title.'" class="alignnone size-full wp-image-'.$id.'" width= 500"/>'; $new_auto_post = array(); $new_auto_post['ID'] = $auto_post_id; $new_auto_post['post_content'] = $content; // Update the post into the database wp_update_post( $new_auto_post );
Above is process of setting the content. I have tried many things but couldn’t get it to work.
Please suggest!!
- The topic ‘tag doesn't display in post content when added via wp_insert_post function’ is closed to new replies.