title: Set featured image using wp_insert_post
body: <pre><code>// Auto post ( Unique File Date ).
  $postData = array(
      'post_category' =&gt; array( $Category ),
      'post_status' =&gt; $Post_Status,
      'post_type' =&gt; $Post_Type
  );
  $post_id = wp_insert_post( $postData );
  
  $getImageFile = 'http://localhost/Multisite/test2/wp-content/uploads/sites/4/Auto Post/twitter.png';
  
  $attach_id = wp_insert_attachment( $postData, $getImageFile, $post_id );
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
  
  $attach_data = wp_generate_attachment_metadata( $attach_id, $getImageFile );
  
  wp_update_attachment_metadata( $attach_id, $attach_data );
  
  set_post_thumbnail( $post_id, $attach_id );
  </code></pre>
  <p>The code above make a post successfully but it is not setting the post featured image. I don't know what I am doing wrong here.</p>