post_is_in_descendant_category
is not a WP function. If you don’t define it, it doesn’t exist. I think that you have read the docs for in_category()
function and have taken post_is_in_descendant_category
from the example without read it completely. Add this code to functions.php or in a plugin:
if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
function post_is_in_descendant_category( $cats, $_post = null ) {
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
}
Now post_is_in_descendant_category()
is defined and you can use it. Remember to use in_category()
or post_is_in_descendant_category()
inside The loop, if not, you need to pass the post ID or object to check.
NOTE: You are using array( '1', '2', '3', )
. The values inside the array are strings; I think you refer to categories with ID 1, 2 and 3. To pass cateogories IDs you have pass the values as integer: array( 1, 2, 3 )
. Also note that post_is_in_descendant_category
only accepts category IDs as integer values.