这将获得所有自定义帖子ctp_slug
分配给home-theater
分类法和带有posts ID的返回数组。post__in
参数将结果限制为仅使用给定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;
}