Get all subcategories IDs from categorie or categorieIDs

admin2025-06-04  3

I'm having trouble to get an array of IDs from subcategories. My code:

$cats_excluded = array_merge( array(get_cat_ID('podjetje'), get_cat_ID('personal'), get_cat_ID('nekategorizirano'), get_cat_ID('razno'), get_cat_ID('sola-2')), (array)$query->get( 'category__not_in' ) );

$args0 = array('child_of' => get_cat_ID('podjetje'));
$args1 = array('child_of' => get_cat_ID('personal'));
$args2 = array('child_of' => get_cat_ID('nekategorizirano'));
$args3 = array('child_of' => get_cat_ID('razno'));
$args4 = array('child_of' => get_cat_ID('sola-2'));

$args = array_merge($args0, $args1, $args2, $args3, $args4);

$categories = get_categories( $args );
foreach($categories as $category)
{
    array_push($cats_excluded,$category->cat_ID);
}

$query->set( 'category__not_in', $cats_excluded)
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748975884a315310.html

最新回复(0)