I use wp-e-commerce. I created a custom post type called “event”. I would like to create new “event” as a parent and hook products under it. When I “hook” a product under post parent “event”, wp-e-commenrce does not appear me this in products at the admin panel. The product exists on database and it’s register. The only way to make this product visible is to set the value 0 to “post_parent” field on wp_post table. Wp-e-commerce by default give 0 to post_parent.
function createProduct($event_id, $attach_id, $attach)
{
// Create product object
$product_name = get_the_title($event_id).'_'.$attach_id;
$evman_product = array(
'post_title' => $product_name,
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'wpsc-product',
'post_parent' => $event_id
);
// Insert the post into the database
$this->unhookFromSavePost(); // see http://codex.wordpress.org/Plugin_API/Action_Reference/save_post#Avoiding_infinite_loops
$evman_the_product_id = wp_insert_post( $evman_product ); //get product's id
$this->hookToSavePost();
//Re-attach attachment to new product
$attach_duplicated = $attach;
$attach_duplicated->post_parent = $evman_the_product_id;
$newAddedAttachment = wp_insert_attachment( $attach_dublicated );
return evman_the_product_id;
}