get_categories()
gives you an array of WP_Term
objects, which has the parent
property. This contains the ID of the parent category. Inside your loop you can do a simple comparison to see, if the current iteration category has the specific parent category’s ID or not, and if it does, skip it.
$parent_id = 123; // change to actual term id
foreach( $categories as $category ) {
if ( $parent_id === $category->parent ) {
continue;
}
// rest of the code...
}