我在函数中创建了一个自定义函数。php检查post\\u是否在\\u substant\\u类别中,我通过一个插件控制它,该插件返回true is a post is in substant类别,it is working well
But it\'s not working in my home.php, 奇怪的是,当我检查家中任何帖子的post\\u是否在\\u genderant\\u类别中时。php结果保持为true
I want to know the reason for that and how to fix it
post\\u的我的代码是\\u子体\\u类别中的\\uif ( ! 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;
}
}
我的插件代码:function check_category(){
global $rtlDir;
if ( $category_to_check = get_term_by( \'slug\', \'category-3\', \'category\' )){
if(post_is_in_descendant_category($category_to_check->term_id)){
$rtlDir = true;
}else{
$rtlDir = false;
}
}
}
add_filter("wp","check_category");