wp_set_object_terms "invalid taxonomy" in own Class
-
Hello, faced with such a problem.
I have Custom post type with Taxonomy, in the functions.php file writing scriptfunction addCategory($post){ $terms = $post['terms']; $post_id = $post['id']; $taxonomy = 'my_taxonomy_name'; $term_taxonomy_ids = wp_set_object_terms( $id, $terms, $taxonomy, true); } addCategory($post);
everything works, the category is added to the post
But when I try to do the same in the class I get an error “invalid taxonomy”
class MyClass{ function addCategory( $post ){ $terms = $post['terms']; $id = $post['id']; $taxonomy = 'my_taxonomy_name'; $term_taxonomy_ids = wp_set_object_terms( $id, $terms, $taxonomy, true ); if ( is_wp_error( $term_taxonomy_ids ) ) { echo $term_taxonomy_ids->get_error_message(); // "invalid taxonomy" } } } $MyClass= new MyClass; $MyClass -> addCategory($_POST); // "invalid taxonomy"
- The topic ‘wp_set_object_terms "invalid taxonomy" in own Class’ is closed to new replies.