How to put an array in is_category

I try to put an array in a is_category():

I have my array like this

$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 )

Now when i put my code

if(is_category(array($mycategory))):
//echo 'it's work';
else:
//echo 'nope';
endif;

It’s don’t work

Thanks for help

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try:

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

if( is_category( $mycategory ) ) {
   echo 'yes';
} else {
   echo 'no';
}

is_category returns true if there are any matches.

You could try this:

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x