【发布时间】:2014-11-05 17:13:34
【问题描述】:
场景:
我有一个帖子类型 portfolio 和一个自定义帖子类型 song,还有一个名为 songs_categories 的自定义分类。
作品集在loop 1内,歌曲在loop 2,在loop 1内。
我需要做的是显示组合中的歌曲,但前提是歌曲category slug(专辑名称)具有组合post_name(专辑名称)的实际价值。
我可以获得所需的值,但在编写过滤所需的实际函数时遇到了麻烦。任何帮助表示赞赏。
<!-- Loop 1 -->
<div class="songs">
<?php
$var1 = $post->post_name;
$my_query = new WP_Query('post_type=song' );
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
<?php $terms = get_the_terms( $post->ID , 'songs_categories' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'songs_categories' );
if( is_wp_error( $term_link ) )
continue;
echo "$var1";
echo "$term->slug";
} ?>
<div class="col one">
<a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
h2><?php the_title(); ?></h2>
<?php
$autor_name = get_post_meta($post->ID, "_cmb_autor_text", false);
if ($autor_name[0]=="") { ?>
<!-- If there are no custom fields, show nothing -->
<?php } else { ?>
<?php foreach($autor_name as $autor_name) {
echo '<p>'.$autor_name.'</p>';
} ?>
<?php } ?>
</div>
<?php endwhile; ?> <!-- End 2nd loop -->
</div> <!-- End songs -->
<?php endif; endwhile; ?>
<?php endif; // password check ?> <!-- End 1st loop -->
【问题讨论】: