2
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;
}

我以编程方式从前端发布产品类型。它将产品类型插入数据库但不返回帖子 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 功能后给出错误。所以我不能为这篇文章添加元数据。

谁能告诉我为什么?

4

0 回答 0