我有以下循环,我试图基于几个值对此进行过滤,以便该循环可以更具体地针对每个选择。
<div class="film-list">
<?php $loop = new WP_Query( array( 'post_type' => 'drama', 'posts_per_page' => -1, 'category' => 'current' ) ); ?><?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$post_id = get_the_id();
$data['episode'] = get_post_meta($post_id, "episode",true);
$data['released'] = get_post_meta($post_id, "released",true);
$data['type'] = get_post_meta($post_id, "type",true);
$data['series'] = strip_tags( get_the_term_list( $wp_query->post->ID, 'drama_category', '', ', ', '' ) );
?>
<div class="item">
<div class="inner">
<a class="poster" href="<?php the_permalink(); ?>"><img alt="<?php print $data['series']; print $data['type']; ?>" src="<?php print $feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>">
<div class="status">
<div class="dub">
<?php print $data['type']; ?>
</div><span class="bar"></span>
<div class="ep">
<?php print $data['episode']; ?>
</div>
</div></a>
<a class="name" data-jtitle="<?php print $data['series']; print $data['type']; ?>" href="<?php the_permalink(); ?>">
<?php print $data['series']; print ' ('; print $data['type']; print ')'; ?>
</a>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
上面的代码是在 drama 的自定义post_type
中显示结果的方法,并且可以完美地工作,但是我想知道如何为仅包含以下内容的帖子制作循环过滤器: $data['type']
部分中的特定字母。
例如
if (strpos($data['type'], 'dub') !== false) {
// run our loop as normal displaying 20 - 30 results
// (whatever our limitation on post_per_page is, this doesn't work but it gives you a better idea of what I want
}