在wordpress中插入前端的产品类型

时间:2013-07-22 12:51:11

标签: wordpress woocommerce

if(isset($_POST['uploadwine']))
{

    global $wpdb,$woocommerce;
        global $current_user;
        $post_status = 'publish'; 
            if(isset($_POST['postid']))
                {
                $postid=$_POST['postid'];
                }else
                                  {
                    $postid='';
                }
            $wine_post = array(
                 'post_title' => $_POST['wine_name'],
                'post_status' => $post_status,
                 'post_author' => $current_user->ID,
                 'post_type' => 'Product',
              );

    if( empty($postid)){

            echo  $postid=wp_insert_post( $wine_post );


        update_post_meta($postid, '_thumbnail_id', $_POST['aaiu_image_id'][0]);

        $product_meta['year'] = $_POST['year'];
        $product_meta['producer'] = $_POST['producer'];
        #$product_meta['grapes_variety'] = $_POST['grapes_variety'];
        $product_meta['area'] = $_POST['area'];
        #$product_meta['tw_share'] = $_POST['Country'];
        $product_meta['color'] = $_POST['Color'];
        $product_meta['good_answer_for_the_smell_test'] = $_POST['Smell'];
        $product_meta['good_answer_for_the_taste_test'] = $_POST['Taste'];
        foreach($product_meta as $key =>$value)
        {
            update_post_meta($postid, $key, $value);
        }
die;
}

我以编程方式从前端发布产品类型。它将产品类型插入数据库但不返回post id。相反,它给了我这个错误"Call to a member function get_product() on a non-object in /srv/data/web/vhosts/www.wiine.me/htdocs/devbeta/wp-content/plugins/woocommerce/woocommerce-core-functions.php on line 32".

get_product()是woocommerce函数可能与wp_insert_post($ wine_post)挂钩。在wp_insert_post函数之后它会出错。所以我不能为这篇文章添加meta。

谁能告诉我为什么?

0 个答案:

没有答案