I have attached my code below. This code previously worked, but has since stopped. I can't understand why the error code is throwing now. I've marked where the error is occuring using // * ISSUE IS RIGHT HERE * //
I have looked through plenty of resources on wp_insert_term but nothing explains why I am getting invalid taxonomy in return/wp error. Can anyone help with this?
$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++;
}
I have attached my code below. This code previously worked, but has since stopped. I can't understand why the error code is throwing now. I've marked where the error is occuring using // * ISSUE IS RIGHT HERE * //
I have looked through plenty of resources on wp_insert_term but nothing explains why I am getting invalid taxonomy in return/wp error. Can anyone help with this?
$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++;
}
Share
Improve this question
asked Oct 3, 2019 at 16:33
JamesJames
1
1
- 1 Depending on your code, check if wp_insert_term is not called before register_taxonomy. – Gbenankpon Arthur Commented Oct 3, 2019 at 18:46
1 Answer
Reset to default 0Move the $make_new['term_id'] inside the block that runs when there is no error.
Do you have your WP_DEBUG on? What is the error message?