【发布时间】:2014-03-12 10:48:27
【问题描述】:
在 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 运算符,还是嵌套数组?
【问题讨论】:
-
您在下面的评论中提到您有许多循环。阅读When should you use WP_Query vs query_posts() vs get_posts()?