This is the code that was needed in order to make it show only the posts (that were of a specific custom post type) that matched the same child category (therefore matching all the other categories):
<!-- other posts -->
<?php
//this gets the lowest hierarchical child term for current post
$categories = get_the_category($post->ID);
foreach($categories as $category) :
$children = get_categories( array ('parent' => $category->term_id ));
$has_children = count($children);
if ( $has_children == 0 ) {
$current_child = $category->name;
}
endforeach;
//this starts the query for the program listings custom post types
$post_type="program_listings";
$tax = 'category';
$tax_terms = wp_get_object_terms($post->ID, 'category');
if ($tax_terms == $category_terms) {
foreach ($tax_terms as $tax_term) {
$args=array(
'post_type' => $post_type,
"$tax" => $tax_term->slug,
'post_status' => 'publish',
'operator' => 'AND',
'posts_per_page' => 5,//limits the listing to 5
'caller_get_posts'=> 1,
'post__not_in' => array ($post->ID),
'orderby' => 'ID', //orders by ID, you could also tell it to order by: ‘author’ ‘title’‘name’‘date’ or ‘rand’
'order' => 'ASC', //tells it the display order should be ascending, DSC would indicate a descending order
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() && $tax_term->name == $current_child)//now only display categories the current post is in
{
echo '<h2>Other programs in this category</h2><ul>';
while ($my_query->have_posts() && $tax_term->name==$current_child ) : $my_query->the_post(); ?>
<li style="margin-left:15px;list-style:none;"><a href="https://wordpress.stackexchange.com/questions/108367/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
}
wp_reset_query();
}
}
echo '</ul>';
?>
<!-- end other posts -->