Post is in descendant category not working in home.php

home.php is an archive of posts, and when you view home.php and function in plugin run, (on ‘wp’ hook) there is no current post.

So the function post_is_in_descendant_category call in_category($descendants, null) that can never return true if there is no current post.

For this reason, you should run the plugin function on 'the_post' action hook, if you want it runs for every post in the archive, something like:

add_filter("the_post", "check_category");

function check_category($post) {
  // here your code
  global $rtlDir;
  if ( $category_to_check = get_term_by( 'slug', 'category-3', 'category' ) ){
    if( post_is_in_descendant_category($category_to_check->term_id, $post) ){
        $rtlDir = true;
    } else {
        $rtlDir = false;
    }
  }
}

This should work, but don’t seems a good solution: this run an additional db query for every post…

If you explain why you run this code, and what you want to obtain probably is possible to find a more performant solution.

error code: 523