I’m trying to insert WooCommerce products into the WordPress database via PHP. A WooCommerce product is just a post with post-type=product, so I thought that this should work:
$mypost = array('post-title' => $secondexplosion[0], 'post-type' => 'product',
'post-status' => 'publish', 'post-content' => $secondexplosion[1],
'post-excerpt' => '');
$postid = wp_insert_post($mypost, true);
$secondexplosion is a String array that contains the post-title and post-content; I checked, and it does not contain null values or anything problematic. Why, then, is wp_insert_post returning the error “Content, title, and excerpt are empty”? Thanks much!
The Codex for wp_insert_post has a lot of useful information:
It looks like you’ve just got a typo in your fields; the expected field names are
post_title
post_type
post_status
post_content
andpost-excerpt
– that’s with underscores, instead of dashes.