This will get all custom post ctp_slug
assigned to any term of home-theater
taxonomy and return array with posts ID. post__in
parameter will limit results to only post with given ID.
$args=[
'post_type' => 'ctp_slug',
'posts_per_page' => -1,
'offset' => 0,
'fields' => 'ids',
'tax_query' => [
[
'taxonomy' => 'home-theater',
'operator' => 'EXISTS',
]
],
'post__in' => [parent_ID],
];
$result = get_posts($args);
Edit #1
function get_sidebar_ads_above_tabs_conditional()
{
global $post;
$parent = $post->post_parent;
$parent_has_tax = (!empty($parent)
&& has_term('home-theater', 'projector_types', $parent))
$returnValue="<div style="margin-top: 20px;">";
if ($parent_has_tax)
{
$returnValue .= '<div>Banner Ad 1</div>';
} else
{
$returnValue .= '<div>Banner Ad 1</div>';
} $returnValue .= '</div>';
return $returnValue;
}