First you need to pass the post_id to this function to use the post_id inside the get_the_category($post_id)
function incomplete_cat_list($post_id = '') {
global $post;
$post_id = ($post_id) ? $post_id : $post->ID;
$first_time = 1;
$categories = get_the_category($post_id);
foreach($categories as $category) {
if ($category->cat_name != 'Category Name') {
if ($first_time == 1) {
echo '<a class="cat-list" href="' . get_category_link(
$category->term_id ) . '" title="' . sprintf( __( "See all %s" ),
$category->name ) . '" ' . '>' . $category->name.'</a>';
$first_time = 0;
}
else {
}
}
}
}
This function already echo
so you don’t need to echo it again. So you should call it like this.
incomplete_cat_list($related_post->ID);
Another thing if you want to stop the loop after you get the first category instead of using this $first_time
variable just use break;
to stop the loop.