Skip Navigation

Resolved

Overview of the issue

Since the WordPress 4.8 release, the tax_query query and get_term_by() functions are returning null in secondary languages when you pass the slug or name parameters.

Workaround

As a workaround for this issue pass the ID parameter instead for tax_query query and get_term_by() function. Additionally, you can use our the wpml_object_id function to recover your term translations:

wpml_object_id example for get_term_by() function
$postid = get_the_ID(); //get current post
$termid = wp_get_object_terms($postid, 'category'); //get terms assigned to post
$termobj = $termid[0]; //use only first term value (can be adjusted)
$term = apply_filters( 'wpml_object_id', $termobj->term_id, 'category' ); //Translate the term ID
$term2 = get_term_by('id', $term, 'category'); //Get the translated term object

2 Responses to “Functions tax_query and get_term_by() return false for slug and name parameters”

  1. How can you get the term ID if get_term_by() is returning null ?!

    Please do not advise updating when bugs like these are still live, things do break..