Reputation: 9800
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
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 );
Upvotes: 3
Views: 3459
Reputation: 2967
wp_insert_attachment creates a post itself if parent id is set to zero.
try:
wp_insert_attachment( $attachment,$fullpathfilename,$post_id);
Upvotes: 3