You are using get_single_term
in a way that would require it to return a value…
$term = get_single_term($post->ID, 'course_locations');
… but you have written it in such a way that it echo
s a value. You should have…
function get_single_term($post_id, $taxonomy) {
$terms = wp_get_object_terms($post_id, $taxonomy);
if(!is_wp_error($terms))
{
return $terms[0]->name;
}
}
I noticed a couple of other things not directly related to the question but worth mentioning.
- You really should be using the AJAX API.
include
ingwp-load.php
like that is a kind of hack, in my opinion, that is no longer necessary. It is also prone to error. Imagine if someone were to move one or more of the content directories. - You should really learn to indent your code. You are going to run into all kinds of headaches trying to debug “flat” code like that.