• Hi everyone. I’ve just started to use WordPress and am working on my own theme. Since my page has to support multiple languages I’ve decided to use the Polylang plugin. Additionally I’ve added a category and its translation in the backend. Let’s call the category names “Services” (for English) and “Dienstleistungen” (for German) So far, so good.

    Now I want to write a function do_something($catname) that generates some HTML code based on the given category and current language. Thus it’s called like do_something("services") in the theme (thus hardcoded parameter) and should use the correct translated category in its logic.

    For that purpose I’ve wanted to use get_cat_ID($catname) or get_term_by('name', $catname, 'category') to get the actual ID and get the translated category ID by calling pll_get_term($cat_term_ID). If the page language is English everything works fine, both get_cat_ID and get_term_by return the correct ID for the parameter “services”. As soon as I switch to German (with Polylang’s Language switcher), both return 0 resp. null. Thus I have no chance to call pll_get_term if the language is switched to something different than English. Maybe I am missing something or have a wrong understanding of these functions. For me it isn’t clear why something like get_cat_ID("services") doesn’t work if the page is set to another language.

Viewing 1 replies (of 1 total)
  • I have also run into this problem. The functions worked properly on WP v4.7.3, before we updated to WP v5.4.2. I have also updated Polylang in case it would help, but it did not.

Viewing 1 replies (of 1 total)
  • The topic ‘get_cat_ID returns 0 if used with Polylang’ is closed to new replies.