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
foreach($categories as $category) {
if ($category->parent == $location_cat) {
echo 'name ) . '" ' . '>' . $category->name.'';

Leave a Reply

Your email address will not be published. Required fields are marked *