Home › Forums › Front-end Issues › Fatal error: Object of class WP_Term could not be converted to string › Reply To: Fatal error: Object of class WP_Term could not be converted to string
Hi there,
I’m encountering a similar issue with my site. After updating some plugins, I started getting an error about converting a WP_Term object to a string, especially when using ACF and Elementor Pro together. The error message I’m getting is quite similar to the one posted here.
In my case, when ACF is enabled, the error appears, but once I disable it, the issue seems to resolve, although that causes other problems with my site’s functionality. It seems like the issue is with how ACF is handling taxonomy fields and Elementor’s dynamic tags.
Here’s how I solved it on my website:
Check ACF Field Settings: I went to the ACF field that was causing the issue and made sure the Return Value for taxonomy fields was set to “Term Name” instead of “Term Object.” This ensured that a string value (the term name) was returned instead of a WP_Term object.
Custom PHP Fix: I also added a small function to handle WP_Term objects, which converts them to a string (the term name) when necessary. Here’s the code I added to my theme’s functions.php:
php
Copy
Edit
function convert_wp_term_to_string($term) {
if (is_a($term, ‘WP_Term’)) {
return $term->name; // Or $term->slug, depending on what you need
}
return $term;
}
This ensured that any WP_Term object passed to ACF or Elementor was converted properly to a string before being processed.
Tested with Other Plugins: Finally, I made sure there were no conflicts with other plugins by disabling them one by one. The issue was only occurring with the combination of ACF and Elementor, so after tweaking the ACF settings and adding the custom PHP, the error was resolved.
If anyone is still facing this issue, I recommend trying these solutions out. They worked for me, and the error no longer appears on my site Cinema Apk.
Thanks in advance!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.