如何将数组放入IS_CATEGORY

时间:2021-05-21 作者:timimi

我尝试将数组放入is\\U类别():

我有这样的阵列

$term_id = 7;
$taxonomy_name = \'category\';
$termchildren = get_term_children( $term_id, $taxonomy_name);
$mycategory= array();
foreach ( $termchildren as $child ) {
$term = get_term_by( \'id\', $child, $taxonomy_name);
$mycategory[] = $term->term_id; 
}


$mycategory =     Array ( [0] => 23 [1] => 33 [2] => 37 [3] => 54 [4] => 56 [5] => 58 [6] => 60 [7] => 62 [8] => 64 [9] => 66 [10] => 68 [11] => 70 [12] => 72 [13] => 74 [14] => 76 )
现在当我把我的代码

if(is_category(array($mycategory))):
//echo \'it\\\'s work\';
else:
//echo \'nope\';
endif;
这是不可行的

谢谢你的帮助

1 个回复
最合适的回答,由SO网友:shanebp 整理而成

尝试:

$mycategory = array(23, 33, 37);

if( is_category( $mycategory ) ) {
   echo \'yes\';
} else {
   echo \'no\';
}
is_category 如果存在任何匹配项,则返回true。

您可以尝试以下操作:

... 
$term = get_term_by( \'id\', $child, $taxonomy_name);
if ( is_category( $term->term_id ) ) {
   $mycategory[] = $term->term_id;
}