This thread is resolved. Here is a description of the problem and solution.
Problem:
Trying to use the
wpml_switch_language
function within a filter to list posts from the default language on a page translated to another language, and can't get the
wpml_switch_language
to work.
Solution:
Firstly, it's important to note that the
wpml_switch_language
action hook must be used with the
pre_get_posts
WordPress hook. This means that you should integrate the language switch into the query modification process. Here's how you can do it:
1. Use the
pre_get_posts
hook to modify the query before it runs.
2. Inside your hooked function, call
do_action('wpml_switch_language', 'all')
to switch the language.
3. Then set up your query arguments and run the query.
For more details and usage examples, you can refer to the following documentation:
Additionally, there are alternative approaches you can consider, such as:
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
This topic contains 1 reply, has 2 voices.
Last updated by 1 year, 7 months ago.
Assisted by: Waqas Bin Hasan.