在Wordpress中,我試圖在循環中顯示數據。在這個特殊的環路我想包括具有以下元數據的所有項目:顯示來自同一陣列,具有不同元數據的多個項目
red
blue
green
我有以下陣列:
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'people',
'meta_key' => 'role',
'meta_compare' => '=',
'orderby' => 'title',
'order' => 'ASC',
'meta_value' => 'red',
)
);
這顯示是red
就好項目。但如何添加到數組,以便它顯示所有項目?
的功能代碼是在這裏:
if($posts)
{ ?>
<h3 class="col-md-12">Red & Blue & Green</h3>
<?php
foreach($posts as $post)
{
?>
<div class="thumb-frame col-md-3 col-xs-6 pull-right">
<a href="#detail<?php echo get_the_id(); ?>" onClick="showDetail('<?php echo get_the_id(); ?>');">
<figure class="thumb">
<img class="img-responsive" src="<?php the_field('portrait_image');?>" alt="<?php the_title(); ?>"/>
<figcaption>
<span><?php the_title(); ?></span>
</figcaption>
</figure>
</a>
</div>
<?php
$num++;
}
}
?>
我新的PHP和我不能確定的語法,但應該有一個OR操作,或者嵌套數組?
你提到你有很多在下面的評論中循環。閱讀[**什麼時候應該使用WP_Query vs query_posts()vs get_posts()?**](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-查詢帖子vs獲取帖子) – brasofilo