我们有一个定制的帖子,有父母和多个子帖子。父类分配给分类法,而不是子分类。
我需要if语句来确定这篇文章是否是具有家庭影院分类法的父母的孩子。
发布于 2018-07-27 06:01:47
这将使所有定制的post ctp_slug
分配给home-theater
分类法的任何术语,并返回带有post ID的数组。post__in
参数将结果限制为只有具有给定ID的post。
$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 = '';
if ($parent_has_tax)
{
$returnValue .= 'Banner Ad 1';
} else
{
$returnValue .= 'Banner Ad 1';
} $returnValue .= '';
return $returnValue;
}
https://wordpress.stackexchange.com/questions/309680
复制相似问题