0
我想通過簡碼顯示來自多個類別的所有帖子。如果我在短代碼屬性中使用一個類別,它將起作用。顯示來自多個陣列的自定義帖子
<?php echo do_shortcode('[people cat_name="lab-members"]'); ?>
但是,當我在shortcode屬性中使用兩個或三個類別它不起作用。
<?php echo do_shortcode('[people cat_name="lab-members, advisors"]'); ?>
這裏是我想要
function mmddl_people_shortcode($atts)
{
// define attributes and their defaults
extract(shortcode_atts(array (
'cat_name' => ''
), $atts));
$args = array (
'post_type' => 'people',
'tax_query' => array (
array (
'taxonomy' => 'people_category',
'field' => 'slug',
'terms' => $cat_name
),
),
);
// get the arguments
$loop = new WP_Query($args);
// the loop
while ($loop->have_posts()) : $loop->the_post(); ?>
<!-- team member -->
<div id="people-<?php the_ID() ?>" <?php post_class('col-sm-6 col-md-3 wow fadeInUp'); ?> >
<div class="team-mate">
<h4><?php the_title(); ?></h4>
<figure class="member-photo">
<!-- member photo -->
<?php
if (has_post_thumbnail()) {
the_post_thumbnail('full', array ('class' => 'img-responsive'));
} else {
echo '<img src="http://placehold.it/450x450" alt="' . get_the_title() . '" class="img-responsive">';
}
?>
</figure>
</div>
</div>
<!-- // team member -->
<?php endwhile;
}
add_shortcode('people', 'mmddl_people_shortcode');
謝謝他的作品:) –