How can I alter this code to accept a slug as well as an ID?
The Codex essentially explains how to do this: if ( $category_to_check = get_term_by( ‘name’, ‘fruit’, ‘category’ )) post_is_in_descendant_category($category_to_check->term_id); https://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category Putting it all together in your function you would have: if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { if (!absint($cat)) … Read more