我不知道这是否可能,但我会尽力解释的。
我有一个定制的post类型(创意)和一个分类(图像排序)。CPT中的每个职位都是一个人(一个创造性的人)。他们可以上传图像,并通过选择它们所属的类别(“图像排序”分类法)对它们进行排序。
有多个创意人员,他们会将图片发布到不同的类别。有的给他们所有人,有的给少数人。
每个创意人员都有自己的页面,并动态列出了他们发布内容的类别。不过,我的问题是,如果有一个创意发布到“cat-1”和“cat-2”,那么每个人都会在各自的页面上列出这些信息。我想要的是只展示‘猫-1’和‘猫-2’的创意,已经张贴到这些类别。如果另一个创意发布到“cat-1”和“cat-3”,我只希望这两个人出现在他的页面上。
这有道理吗?
<ul>
<?php
$terms = get_terms('image-sort');
if ( $terms && !is_wp_error($terms) ) :
foreach ( $terms as $term ) :
?>
<li><a href="?term=<?php esc_attr_e($term->slug); ?>"><?php esc_html_e($term->name); ?</a></li>
<?php endforeach; endif; ?>
</ul>发布于 2014-08-19 16:14:56
不确定我是否理解你,但如果我理解了,试着替换这一行:
$terms = get_terms('image-sort');行如下:
$terms = wp_get_object_terms(get_the_ID(), 'image-sort');编辑
尝试用以下代码获取术语:
<?php
// get all attachments of the current post
$attachments = get_children('post_parent=' . get_the_ID() . '&post_type=attachment&post_status=any&posts_per_page=-1');
// we're saving the terms here
$all_terms = array();
// looping through all attachments
foreach( $attachments as $attachment) {
$terms = wp_get_object_terms($attachment->ID, 'image-sort');
if ($terms) {
// looping through all attachment terms and adding them to the main array
foreach ( $terms as $term ) {
$all_terms[$term->term_id] = $term;
}
}
}
?>https://stackoverflow.com/questions/25384869
复制相似问题