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