WP相关的自定义帖子类型的帖子与子父母关系

时间:2013-03-20 03:32:11

标签: wordpress

我的网站上添加了自定义帖子类型,工作正常。有sevaral custom

为自定义分类添加了

条款。所以,一个帖子的条款和条件不同。子条款。

- 起租1   ---子术语1   ---子术语2   ---子术语3

- 第2学期   ---子术语1   ---子术语2   ---子术语3

假设我的一个帖子属于Term1的Sub term2和Term 2的Sub term3。在单个帖子上

页面我可以显示相同条款的相关帖子。但我想展示相关的帖子

来自特定的一个带有子父关系的术语。逻辑是 “如果当前帖子的任何术语是Term1的子术语,则显示相关的

只有那个子术语的帖子。所以在循环中它总是会检查每个术语,如果它是

term1的孩子与否,如果是,那么它将显示相关的帖子。

如果有人向我提供本节的代码,那就太好了。

以下是我目前在帖子内容下方的单个帖子页面中使用的代码。

<?php
$taxonomyName = "project_categories";
$termID = 48; // This is the parent term id

$args = array(
'tax_query' => array(
array(
    'taxonomy'  => $taxonomyName,
    'field'    => 'id',
    'terms'     => $termID,
    'operator'  => 'IN'
)
),
'post_type' => 'projects',
'post__not_in'          => array( $post->ID ),
'showposts'             => 3,
'orderby'               => 'rand',
'ignore_sticky_posts'   => 1
);

$loop = new wp_query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// The items are being displayed here

endwhile; 
wp_reset_query();
?>

我想要的是:

  • 首先获取当前条款ID及其父条款ID 当前帖子,然后比较每个术语的父ID到定义的 父条款id(48)。

  • 如果任何父ID与48匹配,则获取该子项的id 家长。

  • 最后显示与该子术语相关的相关帖子。

0 个答案:

没有答案