Uncaught Error: Cannot use object of type WP_Error as array
-
after creation of post types product and service. adapted this code for my plugin but keep getting the following error:
“Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in C:\xampp\htdocs\emarket2\wp-content\plugins\entrep-cpt\etn_init_cpt.php:95 Stack trace: #0 C:\xampp\htdocs\emarket2\wp-includes\class-wp-hook.php(288): wpa_show_permalinks(‘http://localhos…’, Object(WP_Post)) #1 C:\xampp\htdocs\emarket2\wp-includes\plugin.php(208): WP_Hook->apply_filters(‘http://localhos…’, Array) #2 C:\xampp\htdocs\emarket2\wp-includes\link-template.php(313): apply_filters(‘post_type_link’, ‘http://localhos…’, Object(WP_Post), false, false) #3 C:\xampp\htdocs\emarket2\wp-includes\link-template.php(150): get_post_permalink(Object(WP_Post), false, false) #4 C:\xampp\htdocs\emarket2\wp-includes\post.php(3800): get_permalink(Object(WP_Post)) #5 C:\xampp\htdocs\emarket2\wp-admin\includes\post.php(666): wp_insert_post(Array) #6 C:\xampp\htdocs\emarket2\wp-admin\post-new.php(66): get_default_post_to_edit(‘service’, true) #7 {main} thrown in C:\xampp\htdocs\emarket2\wp-content\plugins\entrep-cpt\etn_init_cpt.php on line 95”
function wpa_show_permalinks( $post_link, $post ){
if (is_object($post) && $post->post_type == ‘service’){
$terms = wp_get_object_terms( $post->ID, ‘service_category’ );
if($terms){
return str_replace( ‘%service_category%’ , $terms[0]->slug , $post_link);
}
}if (is_object($post) && $post->post_type == ‘product’){
$terms = wp_get_object_terms( $post->ID, ‘product_category’ );
print_r($terms);
if($terms){
return str_replace( ‘%product_category%’ , $terms[0]->slug , $post_link);
}
}
return $post_link;
}
add_filter(‘post_type_link’, ‘wpa_show_permalinks’, 1, 2);this code worked fine prior to 5.1.1.. what are your thoughts on this. tnx
The topic ‘Uncaught Error: Cannot use object of type WP_Error as array’ is closed to new replies.