if
( ! function_exists(
'post_is_in_descendant_category'
) ) :
function
post_is_in_descendant_category(
$cats
,
$_post
= null ) {
foreach
( (
array
)
$cats
as
$cat
) {
$descendants
= get_term_children( (int)
$cat
,
'category'
);
if
(
$descendants
&& in_category(
$descendants
,
$_post
) )
return
true;
}
return
false;
}
function
post_is_in_category_slug(
$slug
){
global
$post
;
$post_id
= ( isset(
$post
->ID) ) ?
$post
->ID :
''
;
if
( in_category(
$slug
,
$post_id
) || post_is_in_descendant_category( get_term_by(
'slug'
,
$slug
,
'category'
),
$post_id
) ){
return
true;
}
else
{
return
false;
}
}
endif
;
if
( ! function_exists(
'post_is_in_descendant_taxonomy'
) ) :
function
post_is_in_descendant_taxonomy(
$terms
,
$taxonomy
,
$_post
= null ) {
foreach
( (
array
)
$terms
as
$term
) {
$descendants
= get_term_children( (int)
$term
,
$taxonomy
);
if
(
$descendants
&& has_term(
$descendants
,
$taxonomy
,
$_post
) )
return
true;
}
return
false;
}
function
post_is_in_taxonomy_slug(
$slug
,
$taxonomy
){
global
$post
;
$post_id
= ( isset(
$post
->ID) ) ?
$post
->ID :
''
;
if
( has_term(
$slug
,
$taxonomy
,
$post_id
) || post_is_in_descendant_taxonomy( get_term_by(
'slug'
,
$slug
,
$taxonomy
),
$taxonomy
,
$post_id
) ){
return
true;
}
else
{
return
false;
}
}
endif
;