我只得到一个职位。当我在一个类别中分配两个职位时。请让我知道如何获得一个类别的所有职位。
<?php foreach ( $terms as $term ) { ?>
<!--<div id="<?php //echo $term_id = $term->term_id;?>" class="tabcontent"><!-->
<?php //echo $term_id = $term->term_id;?>
<?php
//loop the names of the slugs for the portfolio_categories
$terms = get_terms( array ( \'taxonomy\' => \'portfolio_categories\', \'hide_empty\' => false, \'parent\' => 0, \'orderby\' => \'date\', \'order\' => \'DESC\' ));
foreach ($terms as $term) {
$slug= $term->slug;
$term_id = $term->term_id;
$args = array(
\'post_type\' => \'Portfolio\',
\'portfolio_categories\' =>$slug,
\'orderby\' => \'ID\',
\'order\' => \'DESC\',
\'hide_empty\' => 1,
\'posts_per_page\' => 6
);
$posts_query = new WP_Query( $args );
if (have_posts()) :
while ( $posts_query->have_posts() ) : $posts_query->the_post();
//echo \'<div id="\'.$term_id .\'" class="tabcontent1">\';
?>
<div id="<?php echo $term_id = $term->term_id;?>" class="tabcontent">
<?php echo \'<div class="col-1-3">\';?>
<!--<div class="col-1-3"><!-->
<?php echo $term_id = $term->term_id;?>
<?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );?>
<div id="<?php //echo $term_id = $term->term_id;?>" class="wrap-col" >
<div class="item-container">
<a class="fancybox" href="<?php echo $thumbnail[0]; ?>" data-fancybox-group= gallery>
<div class="overlay text-center">
<div class="overlay-inner">
<h4>BAKER CANISTER PUMP</h4>
</div>
</div><img src="<?php echo $thumbnail[0];?>"></a> </div>
</div>
<!-- </div><!-->
<?php echo \'</div>\';//echo \'</div>\';?>
</div>
<?php
endwhile;endif; wp_reset_postdata();
}
aftervar\\u dump($posts\\u query);
最合适的回答,由SO网友:lukgoh 整理而成
$args = array(
\'post_type\' => \'Portfolio\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'portfolio_categories\',
\'terms\' => $slug,
\'field\' => \'slug\',
)
),
\'orderby\' => \'ID\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1
);