[Resolved] WPML redirection not working for custom post type terms
This thread is resolved. Here is a description of the problem and solution.
Problem: The client encountered a bug with WPML where the automatic redirection to the correct language page for custom post type terms was not functioning. The error 'Call to a member function wp_safe_redirect() on null' was identified in 'sitepress-multilingual-cms/classes/query-filtering/class-wpml-query-parser.php' on line 340.
Solution: We recommend the following troubleshooting steps: 1. Ensure you have a full backup of your website and database. 2. Update WordPress to the latest version. 3. Increase the 'WP Memory Limit' to at least 128MB, preferably 256MB. You can do this by adding the following code to your wp-config.php file:
Make sure to add these lines before the 'Happy publishing' comment. 4. Switch to a standard WordPress theme like 2021 or 2023 to ensure the issue is not theme-related. 5. Deactivate all plugins except WPML and its addons to check if the issue persists. 6. Reactivate each plugin one by one, checking for the issue after each activation to identify any conflicts.
I found a bug in WPML. Normally if you enter the slug of one language and prepend the wrong language folder, WPML will automatically fix it and redirect to the correct page. This is not working for custom post type terms.
Example with normal pages, where it is working as expected:
Page with German (/de/test-de) and Italian (/it/test-it). If you navigate to /de/test-it or /it/test-de, WPML will automatically redirect to the correct page.
The issue is in "sitepress-multilingual-cms/classes/query-filtering/class-wpml-query-parser.php"
Exception "Call to a member function wp_safe_redirect() on null" (line 340)
We only have the issue for taxonomies (e.g. custom post type "Stories" with taxonomy "category")
link scan didn't fix the issue. Still the same exception ("Call to a member function wp_safe_redirect() on null" in "sitepress-multilingual-cms/classes/query-filtering/class-wpml-query-parser.php" line 340
Let me know if I should try changing some other settings.
Thank you for the updates and the debug information.
I see a few things need fixing before continuing further. Please try the following:
IMPORTANT: Take full backup of your website and database beforehand. It is highly advised to try the following on a staging/dev site first, so your live website isn't compromised.
- Update WordPress to the latest version.
- Fix “WP Memory Limit” to at least 128MB while 256MB is recommended. See https://wpml.org/home/minimum-requirements/ for detailed information. You can set this in your wp-config.php file by adding following code:
Remember to add these lines before the line where it says:
/* That's all, stop editing! Happy publishing. */
And check for the issue. If it still happens, then please continue with the following:
- Switch to a standard WordPress theme like 2021 or 2023. Because your current theme isn't on our compatibility list (https://wpml.org/theme/) so we can be sure if problem isn't coming from there.
- Deactivate all plugins except WPML and its addons and check for the issue.
- Activate each plugin one-by-one, while keeping check on the issue after a plugin is activated. This way you'll be able to pinpoint a plugin having a conflict (or problem), if any.
Please let me know and I'll try my best to help you further on the matter.
thanks a lot for your help. After testing the issue in an empty WP installation + only WPML installed I found out that it works there.
The issue therefore was with our specific WP setup.
Thanks again for your help.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.