Well, it’s pretty clear, why this problem occurs.
Let’s look at wp_insert_term
documentation:
Return Values
(array|WP_Error)
The Term ID and Term Taxonomy ID. (Example: array(‘term_id’=>12,’term_taxonomy_id’=>34))
As you can see, on success this function returns array. But… If any error occurs, it will return an object of WP_Error type.
So… This Fatal Error occurs, because wp_insert_term
ends with error and the rest of code doesn’t process it correctly.
The simple way to fix this is adding another condition to your if statement like this:
$new_term = wp_insert_term( $term_name, $taxonomy, array( 'slug' => self::term_unique_slug( sanitize_title( $term_name ), $taxonomy, $post_lang ) ) );
if ( !is_wp_error($new_term) && isset( $new_term[ 'term_taxonomy_id' ] ) ) {
...
But this won’t solve the real problem – the error occurring in wp_insert_term
call.
Related Posts:
- WPML : how to determine manually the language in which a given page is displayed
- wp_pagenavi function parameters [closed]
- WPML – Change the language of large number of posts
- Change ICL_LANGUAGE_CODE for WPML
- WPML – Pages not synced?
- WPML returning posts that are not published
- WPML: WP_Query + suppress_filters not working
- Translate front page (WPML) [closed]
- WPML translate without duplicating post [closed]
- WPML – Filter by individual or all languages
- Cannot locate specific link/string using String Translation with WPML? [closed]
- WPML custom post type – not translated
- wpml and languages with different directions
- Redirect user based on his language and country using WPML [closed]
- How to Automatically jump to the corresponding language of the page using WPML plugin in wordpress
- Translate Woocommerce automated emails
- Translation of one of the languages is not displayed on the site
- Latest WPML updates broke my wordpress post categories and menus [closed]
- WPML Translate term meta not synced
- WordPress Popular Posts with WPML
- How to configure the request language WP_Query wpml
- Issue with wp_insert_post and post_content field error Could not update post in the database
- Best pratice to make taxonomy terms translatable without changing slugs?
- What is better for wordpress performace?
- Custom Post Type With Different Views
- How to get posts in different language from WPML Plugin [closed]
- Make theme translatable for WPML
- Object of class WP_Error could not be converted to string
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- How can override a add_filter of a plugin?
- Why isn’t WMPL correctly redirecting users based on browser language? [closed]
- Created pages not showing up in ‘All Pages’ list
- How to group multiple wp_errors together?
- WPML Translating a term/taxonomy programmatically
- Find proper “text domain” within theme
- Why is_wp_error() is not returning false even there’s no defined error
- Fetch ID’s associated with a custom post type when translated with WPML?
- Manipulate Permalink
- Translate database content using __($message) function
- Should I include colon in my msgid in PO file?
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- WPML get permalink to the translated post from the original post
- How to list WP multisite languages
- Getting a PHP Notice when using Pods with WPML [closed]
- Checking return with WP Error
- WordPress notification reports
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Custom rewrite rules not working with WPML
- How to Translate a string of an array inside a class?
- Handle new created WP_Error
- WPML language switcher for custom rewrite rules
- Country switcher, then option to choose language for that country [closed]
- Specific content by country in multiple languages
- Copying database tables to new database
- Error when upload images larger than 1024px [closed]
- How to generate “WP_Error” Object for user login?
- Make dynamic string translatable
- ACF Content with WPML not saving [closed]
- plugin generated unexpected output during activation, but it is empty
- How to display WP Query filters?
- WordPress Translation to french, at -> à not working
- Button doesn’t work in the profile panel
- Line Breaks are stripped off when direction property is found
- Critical error – can’t post comments
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- Syncing WP Database Changes Between Environments: How To Handle Merging w/o touching database
- Structure of multilingual and multiregional directory listing website for translation
- get_posts function not returning any results
- Subcategories randomly not working after page/post/category edit in wordpress. Fix: saving permalinks twice
- Categories In English version showing not canonical URL, instead shows query search result
- To stylize WP_Error messages or not?
- Default media uploader is not showing in wordpress website
- How to change the canonical link from a category or taxonomy archive?
- Change WooCommerce currency programmatically on AJAX request
- WordPress custom block compatability with WPML
- I can’t view the orders on the woocomerce dashboard with the brainblocks plugin
- Bulk assign posts to a category using SQL (MySQL)
- Permalinks don’t update nor link properly
- Rest WP_Error always return null
- Custom Post Type slug and WPML gets 404 error
- Title tag wont change
- Site doesn’t work when updating to SSL using nginx
- WPML CMS Nav and Custom Nav_Walker Undefined Property Notices [closed]
- CSS/JS is not working in multi lang installation
- WPML – Auto Duplicate Post Issue
- Theme RTL semi work but with “?rtl=1” fully work
- Theme isn’t multilanguage ready. How can i still add a second language to the site?
- Wpdb empty result only if language is Russian
- disable WP_error: authentication_failed
- Translate placeholder text in search field
- How to write inner join using posts_clauses?
- Many big issues in the website, WP_Debug not showing
- Warning: warning: call_user_func_array() expects parameter 1 to be a valid callback
- wordpress query making site very slow
- How do I turn off WordPress errors and just have regular old php errors?
- How to use filter in this situation, can not modify the structure using filter
- Core error when calling remove_menu_page
- /wp-admin/ – this link showing me “Index of /wp-admin”/ instead of dashboard
- WPML is blocking WP core update
- I have front error for open website [closed]