WP Error using wp_insert_term

时间:2019-10-03 作者:James

我在下面附上了我的代码。这段代码以前工作过,但后来停止了。我不明白为什么现在抛出错误代码。我已使用//* ISSUE IS RIGHT HERE * //

我已经查阅了大量关于wp\\U insert\\U term的资源,但没有任何东西解释为什么我得到了无效的分类法返回/wp错误。有人能帮忙吗?

$meta_input = array(
                \'cstatus\' => $cstatus,
                \'price\' => $price,
                \'year\' => $year,
                \'miles\' => $miles,
                \'exterior\' => $exterior,
                \'interior\' => $interior,
                \'drive\' => $drive,
                \'transmission\' => $transmission,
                \'petrol\' => $petrol,
                \'engine\' => $engine,
                \'topcategory\' => \'no\',
                \'featured\' => \'no\',
                \'html\' => \'no\',
                \'visitorcounter\' => \'no\',
                \'showgooglemap\' => \'no\',
                \'map_location\' => \'Pensacola Florida\',
                \'map-log\' => \'-87.263980\',
                \'map-lat\' => \'30.495620\',
                \'map-country\' => \'US\',
                \'map-address1\' => \'6200\',
                \'map-address2\' => \'Pensacola Blvd\',
                \'map-address3\' => \'Pensacola Florida\',
                \'map-zip\' => \'32505\',
                \'map-state\' => \'FL\',
            );

            $postarr = array(
                \'ID\' => $post_id,
                \'post_content\' => $post_content,
                \'post_title\' => $post_title,
                \'post_status\' => \'publish\',
                \'post_type\' => \'listing_type\',
                \'post_author\'=>32,
                \'comment_status\' => \'closed\',
                \'guid\' => $guid,
                \'meta_input\' => $meta_input
            );
            $have_guids[$guid] = 1;

            $post_id = wp_insert_post($postarr);

            if($post_id > 0 && $new_post && $image_url)
            {
                Generate_Featured_Image($image_url, $post_id);

                $make_term_exists = get_term_by( \'name\', $make, \'make\', ARRAY_A );

                if($make_term_exists == false){
                    $make_new = wp_insert_term($make,\'make\');

                    if ( ! is_wp_error( $make_new ) )
                    { 
                        // Do Nothing;
                    }
                    else
                    { 
                        echo $make_new->get_error_message(); 
                    }
                    // *** ISSUE IS RIGHT HERE *** //
                    $make_id = $make_new[\'term_id\'];
                }else{
                    $make_id = $make_term_exists[\'term_id\'];
                }


                if($make_id > 0)
                {
                    wp_set_post_terms( $post_id, array($make_id), \'make\' );
                }

                $model_term_exists = get_term_by( \'name\', $model, \'model\', ARRAY_A );
                if($model_term_exists == false){
                    $model_new = wp_insert_term($model, \'model\');
                    $model_id = $model_new[\'term_id\'] ;
                }else{
                    $model_id = $model_term_exists[\'term_id\'];
                }
                if($model_id > 0)
                {
                    wp_set_post_terms( $post_id, array($model_id), \'model\' );
                }
                $add_count++;
            }else if($post_id > 0){
                $update_count++;
            }

1 个回复
SO网友:Lincoln Lemos

将$make\\u new[\'term\\u id\']移动到没有错误时运行的块内。

您是否打开了WP\\U调试?错误消息是什么?