I am adding posts dynamically to wordpress. I am using following code to create post and add a featured image which is working fine but there are 2 problems
- It adds 2 posts 1 with image itself no other content and correct with post with that image as featured image .
-
Featured image in post size large .
$post_id = wp_insert_post( $postdata, true );
//Saving Image from a url
$attachmentId_id = wp_insert_attachment( $attachment,$fullpathfilename,0);
add_post_meta( $post_id, ‘_thumbnail_id’, $attachmentId, true );
wp_insert_attachment creates a post itself if parent id is set to zero.
try: