Background of the issue:
I am trying to manage language visibility on my website using WPML. While I have successfully hidden certain languages from the front-end, I need to ensure that I can still access and manipulate data associated with these hidden languages within the template and plugin code.
the previous support ticker I raised was (frustratingly!) re-written by your support bot. And that probably resulted in your support agent not understanding the important part of my question, which is:
Symptoms:
I am unsure how to access posts of a hidden language in the template or plugin code using the WPML function $sitepress->switch_lang($lang, true).
Questions:
Can I access posts of a hidden language in template or plugin code using $sitepress->switch_lang($lang, true)?
Is there any specific documentation or examples that detail accessing posts of a hidden language in code?
All you need to enable the display for yourself in your user profile.
As long as the code is concerned, I'm unable to verify that if it is the correct code (at this point). But as I can understand and mentioned in the chat, that, instead of referencing to internal methods and classes directly, you should use WPML hooks. A most relevant hook to switch a language is https://wpml.org/wpml-hook/wpml_switch_language/. This action hook allows controlling the language in WordPress queries. It overrides the WPML language global variable used to filter database query requests. However, please consider the note mentioned in the hook's guide.
To confirm the authenticity of your proposed code, I have setup this fresh sandbox site (hidden link - one click login) for you. Can you please add your code the way you want and show me an example? So I can further look into this and can have more information from the team. I've configured WPML with few languages. You 'll need to add one or 2 posts, translate these, hide language(s) as you want, add your code and check.
The topic ‘[Closed] Hide languages on the front-end, but still able to access the’ is closed to new replies.