• How do I disable translation for specific WordPress functions? My plugin (EasyIndex) uses get_terms() and get_term_by() to get the term structures (WP_Term) for taxonomies (in this case categories) selected by the user to produce a given index. However Polylang hooks into the “get_terms_args” filter in those functions and messes with the data so the term data I ask for is not returned but instead I get the term data for translated categories. Am I able to turn off Polylang translations of taxonomies while my plugin is processing so it can retrieve the actual raw term data I need?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Chouby

    (@chouby)

    Hello,

    To stop Polylang filter get_terms(), you can set the parameter lang to something empty. See also https://polylang.pro/doc/developpers-how-to

    For get_term_by(), it’s not possible to add an extra parameter. Initially this function as not filtered but some time ago, the function has been refactored to use get_terms(), but as we cannot add extra parameters we cannot control the behavior in the function call.

    There are however workarounds. You can avoid using get_term_by() and rewrite your code to use get_terms() (what WordPress will ends up to do anyway). You can temporarily remove the Polylang get_terms_args filter.

    Thread Starter Jayce53

    (@jayce53)

    I found I could get around this by setting the lang parameter to “en,pt” (my client’s blog used English and Portuguese) and I did this in a filter than ran before any others in the get_terms_args hook. This fixed it for all calls to get_terms() including the call from get_term_by(). But I’m not entirely sure what the purpose of the lang parameter is. Can you explain that so I can be sure my fix is valid?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable translations for taxonomies’ is closed to new replies.