Get single category of parent category and display in WordPress post

I can’t remember anything and keep running into things like this so I wanted to post this. I found this on the following forum topic

post meta data: display the child category from one parent only

Basically you just need to update Location to say whatever category you are trying to grab the child cat from.

//get categories for this post and only display if the category parent is Location
$location_cat=get_cat_ID('Location');
$categories=get_the_category();
foreach($categories as $category) {
if ($category->parent == $location_cat) {
echo 'name ) . '" ' . '>' . $category->name.'';
}
}
?>