I have got following code.
$postData = array(
'post_category' => array(get_category_id("website")),
'post_content' => 'My website about cars.',
'post_title' => 'my little cars',
'post_type' => 'post',
'post_status' => 'publish',
'tags_input' => 'cars, hobbies'
);
$pID = wp_insert_post($postData);
update_post_meta($pID, "language", "English");
update_post_meta($pID, "author", "John");
And how I can add a post thumbnail? Code written below is incorrect.
$filename = "http://damianc.pl/th.jpg";
$wp_filetype = wp_check_filetype(basename($filename), null);
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $filename ),
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $pID );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
Path to image is well. I have no idea.