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
- WPML – PHP Fatal error: Uncaught Error: Call to undefined function str_contains()
- Best WordPress Multi-language Plugin? [closed]
- Open Source replacement for WPML? [closed]
- WPML with WP_Query serving up all 3 languages [closed]
- get_term_children for immediate children only (not grandchildren)
- [Plugin WPML] : How to create a translation of a post using the WPML API?
- gettext does not translate when called in ajax
- How to remove WPML Generator Meta Tag by theme’s functions.php (override plugin function)? [closed]
- Issue with wp_insert_post and post_content field error Could not update post in the database
- WPML: getting page title in different language
- Gettext details
- Error timed out with succesfull wp_remote_post
- Best pratice to make taxonomy terms translatable without changing slugs?
- What is better for wordpress performace?
- Custom Post Type With Different Views
- Rewrite url for custom post type
- Checking current language in a function
- How to get posts in different language from WPML Plugin [closed]
- Add language/country code to each possible URL
- WPML Get url without outputting
- Comments waiting but no comments found
- How to display error messages using WP_Error class?
- Remove WPML’s home_url filter
- Need to give custom page template for each language in WPML
- How To Write An Inner Join With WP Query
- Make theme translatable for WPML
- Handling nonce generation in AJAX registration process
- Object of class WP_Error could not be converted to string
- Insights into WordPress Multi-Site, Domain Mapped, and Multilanguage site using WPML [closed]
- Unable to display multiple post types in same query (WPML WP_Query)
- 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?
- How to check if wp_update_post was successful
- Why isn’t WMPL correctly redirecting users based on browser language? [closed]
- Created pages not showing up in ‘All Pages’ list
- WordPress multilingual site using page-id.php files
- How to group multiple wp_errors together?
- Unable to show error message using wp_login action
- WPML Translating a term/taxonomy programmatically
- How to use WPML Plugin in contact form 7
- Woocommerce and different checkout field for different countries
- WPML Translated Term
- Find proper “text domain” within theme
- Why is_wp_error() is not returning false even there’s no defined error
- WPML in custom page templates
- How to customize the critical error message?
- Fetch ID’s associated with a custom post type when translated with WPML?
- Error 404 using wpml plugin
- WP_Error not displaying errors
- Theme localization in WPML – .mo file error [closed]
- WPML tables not deleted when removing multisite subsite, need help clearing up my sql-file! [closed]
- Manipulate Permalink
- Translate database content using __($message) function
- Should I include colon in my msgid in PO file?
- WPML custom string translation get outside of container
- Return WP_Error as WP_REST_Response
- 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
- WPML – Set language of inserted post
- How to list WP multisite languages
- Default string not appearing want to translate
- Mysql SELECT posts
- WPML Default Language User Meta [closed]
- Getting a PHP Notice when using Pods with WPML [closed]
- Checking return with WP Error
- category filter doesn’t work in WPML
- WordPress Blank Screen Issue [closed]
- WPML & CFT: keeping custom field file to translation
- WordPress notification reports
- How can I add hyperlink in WP_Error message?
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- WordPress customizer Preview not loading
- A simple method for disabling WPML language switcher when meeting specific circumstances [closed]
- How to force change Network site multi language subdirectory base URL?
- How to save post with different languages and linked them with WPML?
- Cannot use object of type WP_Error
- error Trying to get property of non-object and Cannot use object of type WP_Error as array in
- Redirect some of the languages on a multi-language site
- Custom rewrite rules not working with WPML