To answer your first question
What is the difference between those functions
-
get_terms()
returns an array of terms objects that belongs to a specific taxonomy -
get_the_terms()
returns an array of terms belonging to a post -
the_terms()
displays an HTML formatting string of term names belonging to a post
Because you need your terms not hyperlinked and ordered according to parent, I believe wp_get_object_terms()
will be a better option here. wp_get_object_terms()
also returns an array of terms belonging to a post, but is more flexible. You do pay for this flexibility though as you make an extra db call per post.
With this all in mind, you can try the following: (All code is untested)
$args = [
'orderby' => 'parent',
'order' => 'DESC'
];
$terms = wp_get_object_terms( $post->ID, 'locations', $args );
$names = wp_list_pluck( $terms, 'name' );
$output = implode( ', ', $names );
echo $output;