Get Child Category only


I am using this code to retrieve category:

$post_id = get_the_ID();
  $countries = get_the_terms( $post_id, 'country' );
  $fcountry = $countries[0]->slug;

However this sometimes retrieves the parent category of the countries (in our scenario the continent). How could I make this to always output the child category (i.e. the country)?

JoaMika 1 month 0 Answers 7 views 0

Leave an answer